@Override public Future<Job> submit(Topology topology) { return submit(topology, new JsonObject()); }
@Override public Future<Job> submit(Topology topology) { return submit(topology, new JsonObject()); }
@Override public Future<Job> submit(Topology topology, JsonObject config) { Metrics.counter(topology); StreamScopeSetup.addStreamScopes(topology); return super.submit(topology, config); }
private Job awaitCompleteExecution(Topology t, JsonObject config) throws InterruptedException, ExecutionException { Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t, config); Job job = fj.get(); job.complete(); return job; }
@Test public void jobPeriodicSource() throws Exception { Topology t = newTopology(); AtomicInteger n = new AtomicInteger(0); @SuppressWarnings("unused") TStream<Integer> ints = t.poll(() -> n.incrementAndGet(), 100, TimeUnit.MILLISECONDS); Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t); Job job = fj.get(); assertEquals(Job.State.RUNNING, job.getCurrentState()); Thread.sleep(TimeUnit.SECONDS.toMillis(2)); assertTrue(n.get() > 0); // At least one tuple was processed job.stateChange(Job.Action.CLOSE); assertEquals(Job.State.CLOSED, job.getCurrentState()); }
@Test public void jobProcessSource() throws Exception { Topology t = newTopology(); AtomicInteger n = new AtomicInteger(0); @SuppressWarnings("unused") TStream<Integer> ints = t.generate(() -> n.incrementAndGet()); Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t); Job job = fj.get(); assertEquals(Job.State.RUNNING, job.getCurrentState()); assertEquals(Job.Health.HEALTHY, job.getHealth()); assertEquals("", job.getLastError()); Thread.sleep(TimeUnit.SECONDS.toMillis(2)); assertTrue(n.get() > 0); // At least one tuple was processed job.stateChange(Job.Action.CLOSE); assertEquals(Job.State.CLOSED, job.getCurrentState()); assertEquals(Job.Health.HEALTHY, job.getHealth()); assertEquals("", job.getLastError()); }
@Test(expected = TimeoutException.class) public void jobTimesOut() throws Exception { Topology t = newTopology(); AtomicInteger n = new AtomicInteger(0); @SuppressWarnings("unused") TStream<Integer> ints = t.poll(() -> n.incrementAndGet(), 100, TimeUnit.MILLISECONDS); Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t); Job job = fj.get(); assertEquals(Job.State.RUNNING, job.getCurrentState()); try { job.complete(700, TimeUnit.MILLISECONDS); } finally { assertTrue(n.get() > 0); // At least one tuple was processed assertEquals(Job.State.RUNNING, job.getCurrentState()); assertEquals(Job.Health.HEALTHY, job.getHealth()); assertEquals("", job.getLastError()); } }
/** * Test without a pub-sub service so no * cross job connections will be made. * @throws Exception on failure */ @Test public void testNoService() throws Exception { DirectProvider dp = new DirectProvider(); TStream<String> publishedStream = createPublisher(dp, "t1", String.class, getStrs()); Tester testPub = publishedStream.topology().getTester(); Condition<Long> tcPub = testPub.tupleCount(publishedStream, 3); TStream<String> subscribedStream = createSubscriber(dp, "t1", String.class); Tester testSub = subscribedStream.topology().getTester(); Condition<Long> tcSub = testSub.tupleCount(subscribedStream, 0); // Expect none Job js = dp.submit(subscribedStream.topology()).get(); Job jp = dp.submit(publishedStream.topology()).get(); Thread.sleep(1500); assertTrue(tcPub.valid()); assertTrue(tcSub.valid()); js.stateChange(Action.CLOSE); jp.stateChange(Action.CLOSE); }
@Test(expected = ExecutionException.class) public void jobProcessSourceError() throws Exception { Topology t = newTopology(); AtomicInteger n = new AtomicInteger(0); TStream<Integer> ints = t.generate(() -> n.incrementAndGet()); ints.pipe(new FailedOplet<Integer>(12, 100)); Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t); Job job = fj.get(); assertEquals(Job.State.RUNNING, job.getCurrentState()); try { job.complete(10, TimeUnit.SECONDS); } finally { // RUNNING even though execution error assertEquals(Job.State.RUNNING, job.getCurrentState()); assertEquals(Job.Health.UNHEALTHY, job.getHealth()); assertEquals("java.lang.RuntimeException: Expected Test Exception", job.getLastError()); } }
@Test(expected = ExecutionException.class) public void jobPeriodicSourceError() throws Exception { Topology t = newTopology(); AtomicInteger n = new AtomicInteger(0); TStream<Integer> ints = t.poll(() -> n.incrementAndGet(), 100, TimeUnit.MILLISECONDS); ints.pipe(new FailedOplet<Integer>(5, 0)); Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t); Job job = fj.get(); assertEquals(Job.State.RUNNING, job.getCurrentState()); try { job.complete(10, TimeUnit.SECONDS); } finally { // RUNNING even though execution error assertEquals(Job.State.RUNNING, job.getCurrentState()); assertEquals(Job.Health.UNHEALTHY, job.getHealth()); assertEquals("java.lang.RuntimeException: Expected Test Exception", job.getLastError()); } }
Future<Job> fj = ((DirectProvider)getTopologyProvider()).submit(t); Job job = fj.get(); assertEquals(Job.State.RUNNING, job.getCurrentState());
@Test(timeout=10000) public void testProviderServiceSingleSubscriber() throws Exception { DirectProvider dp = new DirectProvider(); dp.getServices().addService(PublishSubscribeService.class, new ProviderPubSub()); TStream<String> publishedStream = createPublisher(dp, "t1", String.class, getStrs()); Tester testPub = publishedStream.topology().getTester(); Condition<List<String>> tcPub = testPub.streamContents(publishedStream, getStrs()); TStream<String> subscribedStream = createSubscriber(dp, "t1", String.class); Tester testSub = subscribedStream.topology().getTester(); Condition<List<String>> tcSub = testSub.streamContents(subscribedStream, getStrs()); // Expect all tuples Job js = dp.submit(subscribedStream.topology()).get(); // Give the subscriber a chance to setup. while (js.getCurrentState() != State.RUNNING) Thread.sleep(50); Job jp = dp.submit(publishedStream.topology()).get(); while (!tcSub.valid() || !tcPub.valid()) Thread.sleep(50); assertTrue(tcPub.valid()); assertTrue(tcSub.valid()); js.stateChange(Action.CLOSE); jp.stateChange(Action.CLOSE); }