changeset 2038:d9578542296b

Add test for vmStatusChanged() when createVmListener() throws exception. Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-December/021795.html PR3257
author Severin Gehwolf <sgehwolf@redhat.com>
date Tue, 29 Nov 2016 11:22:49 +0100
parents 15c2184f097b
children 89807d0b1dfe
files agent/core/src/test/java/com/redhat/thermostat/backend/HostPollingBackendTest.java agent/core/src/test/java/com/redhat/thermostat/backend/VmListenerBackendTest.java agent/core/src/test/java/com/redhat/thermostat/backend/VmPollingBackendTest.java agent/core/src/test/java/com/redhat/thermostat/backend/internal/VmListenerWrapperTest.java
diffstat 4 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/HostPollingBackendTest.java	Mon Dec 05 12:22:44 2016 +0100
+++ b/agent/core/src/test/java/com/redhat/thermostat/backend/HostPollingBackendTest.java	Tue Nov 29 11:22:49 2016 +0100
@@ -50,6 +50,7 @@
 
 import com.redhat.thermostat.common.NotImplementedException;
 import com.redhat.thermostat.common.Version;
+import com.redhat.thermostat.test.Bug;
 
 public class HostPollingBackendTest {
 
@@ -81,6 +82,9 @@
      * If an action throws exceptions repeatedly, that action shall get
      * disabled/unregistered.
      */
+    @Bug(id = "3257",
+         summary = "Adverse Backend breaks other Backends badly ",
+         url = "http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=3257")
     @Test
     public void testDoScheduledActionsWithExceptions() {
         final int beyondExceptionThreshold = 13; // Anything beyond 10 will do
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/VmListenerBackendTest.java	Mon Dec 05 12:22:44 2016 +0100
+++ b/agent/core/src/test/java/com/redhat/thermostat/backend/VmListenerBackendTest.java	Tue Nov 29 11:22:49 2016 +0100
@@ -38,6 +38,7 @@
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
@@ -54,6 +55,7 @@
 import com.redhat.thermostat.agent.VmStatusListenerRegistrar;
 import com.redhat.thermostat.backend.internal.VmMonitor;
 import com.redhat.thermostat.storage.core.WriterID;
+import com.redhat.thermostat.test.Bug;
 
 public class VmListenerBackendTest {
     private static final String VM_ID = "vmId";
@@ -127,6 +129,29 @@
         backend.vmStatusChanged(Status.VM_STARTED, VM_ID, VM_PID);
         verify(monitor).handleNewVm(listener, VM_PID);
     }
+    
+    /**
+     * createVmListener() might be plugin-supplied code. When creating the
+     * listener fails due to exceptions, other listeners should still continue
+     * to work. That is, the exception of creating one listener must not be
+     * propagated.
+     */
+    @Bug(id = "3257",
+         summary = "Adverse Backend breaks other Backends badly ",
+         url = "http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=3257")
+    @Test
+    public void testNewVMCreateListenerWithExceptions() {
+        VmStatusListenerRegistrar customRegistrar = mock(VmStatusListenerRegistrar.class);
+        WriterID wid = mock(WriterID.class);
+        VmListenerBackend testBackend = new ExceptionThrowingCreateVmListenerBackend(
+                "Test Backend", "Backend for test", "Test Co.",
+                "0.0.0", customRegistrar, wid);
+        testBackend.setObserveNewJvm(true);
+        VmMonitor testMonitor = mock(VmMonitor.class);
+        testBackend.setMonitor(testMonitor);
+        testBackend.vmStatusChanged(Status.VM_STARTED, VM_ID, VM_PID);
+        verify(testMonitor, times(0)).handleNewVm(any(VmUpdateListener.class), any(int.class));
+    }
 
     @Test
     public void testAlreadyRunningVM() {
@@ -173,6 +198,19 @@
         }
         
     }
+    
+    private class ExceptionThrowingCreateVmListenerBackend extends TestBackend {
+        
+        public ExceptionThrowingCreateVmListenerBackend(String name, String description, String vendor,
+                String version, VmStatusListenerRegistrar registrar, WriterID writerId) {
+            super(name, description, vendor, version, registrar, writerId);
+        }
+        
+        @Override
+        protected VmUpdateListener createVmListener(String writerId, String vmId, int pid) {
+            throw new RuntimeException("createVmListener() testing!");
+        }
+    }
 
 }
 
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/VmPollingBackendTest.java	Mon Dec 05 12:22:44 2016 +0100
+++ b/agent/core/src/test/java/com/redhat/thermostat/backend/VmPollingBackendTest.java	Tue Nov 29 11:22:49 2016 +0100
@@ -54,6 +54,7 @@
 import com.redhat.thermostat.agent.VmStatusListener.Status;
 import com.redhat.thermostat.agent.VmStatusListenerRegistrar;
 import com.redhat.thermostat.common.Version;
+import com.redhat.thermostat.test.Bug;
 
 public class VmPollingBackendTest {
 
@@ -87,6 +88,9 @@
      * If an action throws exceptions repeatedly, that action shall get
      * disabled/unregistered.
      */
+    @Bug(id = "3257",
+         summary = "Adverse Backend breaks other Backends badly ",
+         url = "http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=3257")
     @Test
     public void testDoScheduledActionsWithExceptions() {
         final int beyondExceptionThreshold = 13; // anything beyond 10 will do
--- a/agent/core/src/test/java/com/redhat/thermostat/backend/internal/VmListenerWrapperTest.java	Mon Dec 05 12:22:44 2016 +0100
+++ b/agent/core/src/test/java/com/redhat/thermostat/backend/internal/VmListenerWrapperTest.java	Tue Nov 29 11:22:49 2016 +0100
@@ -50,6 +50,7 @@
 import com.redhat.thermostat.backend.VmUpdate;
 import com.redhat.thermostat.backend.VmUpdateException;
 import com.redhat.thermostat.backend.VmUpdateListener;
+import com.redhat.thermostat.test.Bug;
 
 import sun.jvmstat.monitor.Monitor;
 import sun.jvmstat.monitor.MonitorException;
@@ -74,6 +75,9 @@
      * from the JVM beyond a threshold.
      * @throws MonitorException 
      */
+    @Bug(id = "3257",
+         summary = "Adverse Backend breaks other Backends badly ",
+         url = "http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=3257")
     @Test
     public void testMonitorsUpdatedListenerExceptions() throws MonitorException {
         final int beyondThresholdLimit = 11;