@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testDedup() { List<DummyEvent> events = Lists.newArrayList(); Calendar calendar = Calendar.getInstance(); for (int i = 0; i < 10; i++) { events.add(new DummyEvent(i, calendar.getTimeInMillis())); } events.add(new DummyEvent(5, calendar.getTimeInMillis())); com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributes = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap(); attributes.put(DAG.APPLICATION_ID, APP_ID); attributes.put(DAG.APPLICATION_PATH, applicationPath); deduper.setup(new OperatorContextTestHelper.TestIdOperatorContext(OPERATOR_ID, attributes)); CollectorTestSink collectorTestSink = new CollectorTestSink<DummyEvent>(); deduper.output.setSink(collectorTestSink); logger.debug("start round 0"); deduper.beginWindow(0); testRound(events); deduper.handleIdleTime(); deduper.endWindow(); Assert.assertEquals("output tuples", 10, collectorTestSink.collectedTuples.size()); collectorTestSink.clear(); logger.debug("end round 0"); logger.debug("start round 1"); deduper.beginWindow(1); testRound(events); deduper.handleIdleTime(); deduper.endWindow(); Assert.assertEquals("output tuples", 0, collectorTestSink.collectedTuples.size()); collectorTestSink.clear(); logger.debug("end round 1"); // Test the sliding window try { Thread.sleep(1500); } catch (InterruptedException e) { throw new RuntimeException(e); } deduper.handleIdleTime(); long now = System.currentTimeMillis(); for (int i = 10; i < 15; i++) { events.add(new DummyEvent(i, now)); } logger.debug("start round 2"); deduper.beginWindow(2); testRound(events); deduper.handleIdleTime(); deduper.endWindow(); Assert.assertEquals("output tuples", 5, collectorTestSink.collectedTuples.size()); collectorTestSink.clear(); logger.debug("end round 2"); deduper.teardown(); }
@Test public void testDeduperRedeploy() throws Exception { com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributes = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap(); attributes.put(DAG.APPLICATION_ID, APP_ID); attributes.put(DAG.APPLICATION_PATH, applicationPath); deduper.addEventManuallyToWaiting(new DummyEvent(100, System.currentTimeMillis())); deduper.setup(new OperatorContextTestHelper.TestIdOperatorContext(0, attributes)); eventBucketExchanger.exchange(null, 500, TimeUnit.MILLISECONDS); deduper.endWindow(); deduper.teardown(); }