# HG changeset patch # User Severin Gehwolf # Date 1480414969 -3600 # Node ID d9578542296b237e361cf52fbfb6a5ef089653b0 # Parent 15c2184f097bcaa408fbcbad10d5dcfc725e306b Add test for vmStatusChanged() when createVmListener() throws exception. Reviewed-by: neugens Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-December/021795.html PR3257 diff -r 15c2184f097b -r d9578542296b agent/core/src/test/java/com/redhat/thermostat/backend/HostPollingBackendTest.java --- 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 diff -r 15c2184f097b -r d9578542296b agent/core/src/test/java/com/redhat/thermostat/backend/VmListenerBackendTest.java --- 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!"); + } + } } diff -r 15c2184f097b -r d9578542296b agent/core/src/test/java/com/redhat/thermostat/backend/VmPollingBackendTest.java --- 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 diff -r 15c2184f097b -r d9578542296b agent/core/src/test/java/com/redhat/thermostat/backend/internal/VmListenerWrapperTest.java --- 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;