SiddhiHandler implements RestListener, EventHandler<MapEvent> { @Override public synchronized void remove(String id) throws RestException { SiddhiPlan siddhiPlan = siddhiPlans.get(id); if (siddhiPlan != null) { siddhiPlan.stop(); siddhiPlans.remove(id); save(); log.info("Siddhi plan with the id {} has been removed", id); log.info("Current queries: {}", siddhiPlans.keySet()); } else { throw new RestNotFoundException("Siddhi plan with id " + id + " is not present"); } } SiddhiHandler(Sink eventReceiver);  SiddhiHandler(); void stop(); Map<String, SiddhiPlan> getSiddhiPlans(); @Override void onEvent(MapEvent mapEvent, long sequence, boolean endOfBatch); @Override void add(Map<String, Object> element); synchronized void add(SiddhiPlan siddhiPlan); @Override synchronized void remove(String id); @Override synchronized void synchronize(List<Map<String, Object>> elements); @Override List<Map<String, Object>> list(); synchronized void save(); synchronized void restore();  }
@Test public void remove() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); Map<String, Object> executionPlanMap = new HashMap<>(); Map<String, String> outputTopics = new HashMap<>(); outputTopics.put("testOutput", "outputTopic"); executionPlanMap.put("id", "testID"); executionPlanMap.put("input", Arrays.asList("test", "test2")); executionPlanMap.put("output", outputTopics); executionPlanMap.put("executionPlan", "from test select a insert into testOutput"); siddhiHandler.add(executionPlanMap); siddhiHandler.remove("testID"); assertTrue(siddhiHandler.getSiddhiPlans().isEmpty()); }
@Test(expected = RestNotFoundException.class) public void removeNotPresent() throws RestException { SiddhiHandler siddhiHandler = new SiddhiHandler(); siddhiHandler.remove("testID"); }