MockitoAnnotations.initMocks(this);
}
@Test
void testTerminateNow() {
TestChaosMonkeyContext ctx = new TestChaosMonkeyContext("ondemandTermination.properties");
String input = "{\"eventType\":\"CHAOS_TERMINATION\",\"groupType\":\"TYPE_C\",\"groupName\":\"name4\"}";
Assert.assertEquals(ctx.selectedOn().size(), 0);
Assert.assertEquals(ctx.terminated().size(), 0);
ChaosMonkeyResource resource = new ChaosMonkeyResource(new BasicChaosMonkey(ctx));
validateAddEventResult(resource, input, Response.Status.OK);
Assert.assertEquals(ctx.selectedOn().size(), 1);
Assert.assertEquals(ctx.terminated().size(), 1);
validateAddEventResult(resource, input, Response.Status.OK);
Assert.assertEquals(ctx.selectedOn().size(), 2);
Assert.assertEquals(ctx.terminated().size(), 2);
// TYPE_C.name4 only has two instances, so the 3rd ondemand termination
// will not terminate anything.
validateAddEventResult(resource, input, Response.Status.GONE);
Assert.assertEquals(ctx.selectedOn().size(), 3);
Assert.assertEquals(ctx.terminated().size(), 2);
// Try a different type will work
input = "{\"eventType\":\"CHAOS_TERMINATION\",\"groupType\":\"TYPE_C\",\"groupName\":\"name5\"}";
validateAddEventResult(resource, input, Response.Status.OK);
Assert.assertEquals(ctx.selectedOn().size(), 4);
Assert.assertEquals(ctx.terminated().size(), 3);
}