@Test public void testHandleRequest() { DynamodbEvent input = new DynamodbEvent(); List<DynamodbStreamRecord> records = new ArrayList<>(); DynamodbStreamRecord record = new DynamodbStreamRecord(); StreamRecord r = new StreamRecord(); Map<String, AttributeValue> image = new HashMap<>(); image.put("status", new AttributeValue("ACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setNewImage(image); record.setEventName(OperationType.INSERT); record.setDynamodb(r); records.add(record); input.setRecords(records); Container container = mock(Container.class); Controller1 controller1 = new Controller1(); doReturn(controller1).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); SchedulerHandler handler = new SchedulerHandler(); handler.handleRequest(input, null); assertTrue(controller1.activated); input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("INACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setNewImage(image); record.setEventName(OperationType.INSERT); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); controller1 = new Controller1(); doReturn(controller1).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); handler.handleRequest(input, null); assertFalse(controller1.activated); input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("INACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setNewImage(image); record.setEventName(OperationType.MODIFY); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); controller1 = new Controller1(); doReturn(controller1).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); handler.handleRequest(input, null); assertTrue(controller1.deactivated); input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("ACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setNewImage(image); record.setEventName(OperationType.MODIFY); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); controller1 = new Controller1(); doReturn(controller1).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); handler.handleRequest(input, null); assertFalse(controller1.deactivated); input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("ACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setOldImage(image); record.setEventName(OperationType.REMOVE); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); controller1 = new Controller1(); doReturn(controller1).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); handler.handleRequest(input, null); assertTrue(controller1.deactivated); input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("INACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setOldImage(image); record.setEventName(OperationType.REMOVE); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); controller1 = new Controller1(); doReturn(controller1).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); handler.handleRequest(input, null); assertFalse(controller1.deactivated); input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("ACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setNewImage(image); record.setEventName(OperationType.INSERT); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); doReturn(new Controller2()).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); try { handler.handleRequest(input, null); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage(), is("hello")); } input = new DynamodbEvent(); records = new ArrayList<>(); record = new DynamodbStreamRecord(); r = new StreamRecord(); image = new HashMap<>(); image.put("status", new AttributeValue("INACTIVE")); image.put("name", new AttributeValue("fault-1")); image.put("id", new AttributeValue("fault-id-1")); image.put("params", new AttributeValue("{}")); r.setNewImage(image); record.setEventName(OperationType.MODIFY); record.setDynamodb(r); records.add(record); input.setRecords(records); container = mock(Container.class); doReturn(new Controller2()).when(container).fault(anyString(), anyString(), anyString()); Prodigy.container(container); handler = new SchedulerHandler(); try { handler.handleRequest(input, null); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage(), is("hello")); } }
@Override public Void handleRequest(DynamodbEvent input, Context context) { try { input.getRecords().forEach(r -> { OperationType type = OperationType.valueOf(r.getEventName()); StreamRecord record = r.getDynamodb(); if (type == OperationType.INSERT) { if (record.getNewImage().get("status").getS().equals("ACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Activating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.activate(); log.info("Fault id [" + id + "] activated"); } } } else if (type == OperationType.MODIFY) { if (record.getNewImage().get("status").getS().equals("INACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } else { if (record.getOldImage().get("status").getS().equals("ACTIVE")) { String name = record.getOldImage().get("name").getS(); String id = record.getOldImage().get("id").getS(); String params = record.getOldImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } }); } catch (RuntimeException e) { log.error(e.getMessage(), e); throw e; } return null; }
SchedulerHandler implements RequestHandler<DynamodbEvent, Void> { @Override public Void handleRequest(DynamodbEvent input, Context context) { try { input.getRecords().forEach(r -> { OperationType type = OperationType.valueOf(r.getEventName()); StreamRecord record = r.getDynamodb(); if (type == OperationType.INSERT) { if (record.getNewImage().get("status").getS().equals("ACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Activating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.activate(); log.info("Fault id [" + id + "] activated"); } } } else if (type == OperationType.MODIFY) { if (record.getNewImage().get("status").getS().equals("INACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } else { if (record.getOldImage().get("status").getS().equals("ACTIVE")) { String name = record.getOldImage().get("name").getS(); String id = record.getOldImage().get("id").getS(); String params = record.getOldImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } }); } catch (RuntimeException e) { log.error(e.getMessage(), e); throw e; } return null; } }
SchedulerHandler implements RequestHandler<DynamodbEvent, Void> { @Override public Void handleRequest(DynamodbEvent input, Context context) { try { input.getRecords().forEach(r -> { OperationType type = OperationType.valueOf(r.getEventName()); StreamRecord record = r.getDynamodb(); if (type == OperationType.INSERT) { if (record.getNewImage().get("status").getS().equals("ACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Activating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.activate(); log.info("Fault id [" + id + "] activated"); } } } else if (type == OperationType.MODIFY) { if (record.getNewImage().get("status").getS().equals("INACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } else { if (record.getOldImage().get("status").getS().equals("ACTIVE")) { String name = record.getOldImage().get("name").getS(); String id = record.getOldImage().get("id").getS(); String params = record.getOldImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } }); } catch (RuntimeException e) { log.error(e.getMessage(), e); throw e; } return null; }  }
SchedulerHandler implements RequestHandler<DynamodbEvent, Void> { @Override public Void handleRequest(DynamodbEvent input, Context context) { try { input.getRecords().forEach(r -> { OperationType type = OperationType.valueOf(r.getEventName()); StreamRecord record = r.getDynamodb(); if (type == OperationType.INSERT) { if (record.getNewImage().get("status").getS().equals("ACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Activating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.activate(); log.info("Fault id [" + id + "] activated"); } } } else if (type == OperationType.MODIFY) { if (record.getNewImage().get("status").getS().equals("INACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } else { if (record.getOldImage().get("status").getS().equals("ACTIVE")) { String name = record.getOldImage().get("name").getS(); String id = record.getOldImage().get("id").getS(); String params = record.getOldImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } }); } catch (RuntimeException e) { log.error(e.getMessage(), e); throw e; } return null; }  @Override Void handleRequest(DynamodbEvent input, Context context); }
SchedulerHandler implements RequestHandler<DynamodbEvent, Void> { @Override public Void handleRequest(DynamodbEvent input, Context context) { try { input.getRecords().forEach(r -> { OperationType type = OperationType.valueOf(r.getEventName()); StreamRecord record = r.getDynamodb(); if (type == OperationType.INSERT) { if (record.getNewImage().get("status").getS().equals("ACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Activating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.activate(); log.info("Fault id [" + id + "] activated"); } } } else if (type == OperationType.MODIFY) { if (record.getNewImage().get("status").getS().equals("INACTIVE")) { String name = record.getNewImage().get("name").getS(); String id = record.getNewImage().get("id").getS(); String params = record.getNewImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } else { if (record.getOldImage().get("status").getS().equals("ACTIVE")) { String name = record.getOldImage().get("name").getS(); String id = record.getOldImage().get("id").getS(); String params = record.getOldImage().get("params").getS(); log.info("Deactivating fault id [" + id + "]"); Fault fault = Prodigy.container().fault(name, id, params); if (fault instanceof Controller) { Controller controller = (Controller) fault; controller.deactivate(); log.info("Fault id [" + id + "] deactivated"); } } } }); } catch (RuntimeException e) { log.error(e.getMessage(), e); throw e; } return null; }  @Override Void handleRequest(DynamodbEvent input, Context context);  }