brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drigod...@apache.org
Subject [1/5] brooklyn-server git commit: WinRM feed (entity initialisers): add rebind tests
Date Fri, 28 Apr 2017 11:17:32 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 33abb3060 -> b7f13c147


WinRM feed (entity initialisers): add rebind tests

Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b09c97f6
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b09c97f6
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b09c97f6

Branch: refs/heads/master
Commit: b09c97f697a8f707f36e6072a359ebdd2bcdb472
Parents: a6457a6
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Apr 27 13:02:45 2017 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Apr 27 13:03:23 2017 +0100

----------------------------------------------------------------------
 .../feed/windows/WinRmCommandSensorTest.java    |  81 +++++++++++++++
 .../WindowsPerformanceCounterSensorsTest.java   | 102 +++++++++++++++++++
 2 files changed, 183 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b09c97f6/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WinRmCommandSensorTest.java
----------------------------------------------------------------------
diff --git a/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WinRmCommandSensorTest.java
b/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WinRmCommandSensorTest.java
new file mode 100644
index 0000000..dcadca0
--- /dev/null
+++ b/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WinRmCommandSensorTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.feed.windows;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
+import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.core.sensor.windows.WinRmCommandSensor;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.internal.winrm.RecordingWinRmTool;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class WinRmCommandSensorTest extends RebindTestFixtureWithApp {
+
+    private Location loc;
+    
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        loc = mgmt().getLocationManager().createLocation(LocationSpec.create(WinRmMachineLocation.class)
+                .configure("address", "1.2.3.4")
+                .configure(WinRmMachineLocation.WINRM_TOOL_CLASS, RecordingWinRmTool.class.getName()));
+        
+        RecordingWinRmTool.clear();
+    }
+
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        RecordingWinRmTool.clear();
+    }
+
+    @Test
+    public void testRebind() throws Exception {
+        RecordingWinRmTool.setCustomResponse(".*mycommand.*", new RecordingWinRmTool.CustomResponse(0,
"myval", ""));
+        
+        Entity entity = app().createAndManageChild(EntitySpec.create(TestEntity.class)
+                .addInitializer(new WinRmCommandSensor<String>(ConfigBag.newInstance(ImmutableMap.of(
+                        WinRmCommandSensor.SENSOR_PERIOD, "1ms",
+                        WinRmCommandSensor.SENSOR_COMMAND, "mycommand",
+                        WinRmCommandSensor.SENSOR_NAME, "mysensor")))));
+        
+        app().start(ImmutableList.of(loc));
+
+        EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor("mysensor"),
"myval");
+        
+        rebind();
+        
+        RecordingWinRmTool.setCustomResponse(".*mycommand.*", new RecordingWinRmTool.CustomResponse(0,
"myval2", ""));
+        EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor("mysensor"),
"myval2");
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b09c97f6/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterSensorsTest.java
----------------------------------------------------------------------
diff --git a/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterSensorsTest.java
b/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterSensorsTest.java
new file mode 100644
index 0000000..5df4f5c
--- /dev/null
+++ b/software/winrm/src/test/java/org/apache/brooklyn/feed/windows/WindowsPerformanceCounterSensorsTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.feed.windows;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
+import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.core.sensor.windows.WindowsPerformanceCounterSensors;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.internal.winrm.RecordingWinRmTool;
+import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+public class WindowsPerformanceCounterSensorsTest extends RebindTestFixtureWithApp {
+
+    @SuppressWarnings("unused")
+    private static final Logger log = LoggerFactory.getLogger(WindowsPerformanceCounterFeedTest.class);
+
+    private Location loc;
+    
+    @BeforeMethod(alwaysRun=true)
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        loc = mgmt().getLocationManager().createLocation(LocationSpec.create(WinRmMachineLocation.class)
+                .configure("address", "1.2.3.4")
+                .configure(WinRmMachineLocation.WINRM_TOOL_CLASS, RecordingWinRmTool.class.getName()));
+        
+        RecordingWinRmTool.clear();
+    }
+
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        super.tearDown();
+        RecordingWinRmTool.clear();
+    }
+
+    @Test
+    public void testRebind() throws Exception {
+        String response = generateCounterReponse("mycounter", "myval");
+        RecordingWinRmTool.setCustomResponse(".*mycounter.*", new RecordingWinRmTool.CustomResponse(0,
response, ""));
+                
+        Entity entity = app().createAndManageChild(EntitySpec.create(TestEntity.class)
+                .addInitializer(new WindowsPerformanceCounterSensors(ConfigBag.newInstance(ImmutableMap.of(
+                        WindowsPerformanceCounterSensors.PERIOD, "1ms",
+                        WindowsPerformanceCounterSensors.PERFORMANCE_COUNTERS, ImmutableSet.of(
+                                ImmutableMap.of(
+                                        "name", "mysensor",
+                                        "sensorType", java.lang.String.class.getName(), //FIXME
+                                        "counter", "\\mycounter")))))));
+        
+        app().start(ImmutableList.of(loc));
+        
+        EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor("mysensor"),
"myval");
+        
+        rebind();
+        
+        String response2 = generateCounterReponse("mycounter", "myval2");
+        RecordingWinRmTool.setCustomResponse(".*mycounter.*", new RecordingWinRmTool.CustomResponse(0,
response2, ""));
+        EntityAsserts.assertAttributeEqualsEventually(entity, Sensors.newStringSensor("mysensor"),
"myval2");
+    }
+    
+    private String generateCounterReponse(String counterName, String val) {
+        String firstPart = "\\\\machine.name\\" + counterName;
+        return new StringBuilder()
+                .append(firstPart)
+                .append(Strings.repeat(" ", 200 - (firstPart.length() + val.length())))
+                .append(val)
+                .toString();
+    }
+}


Mime
View raw message