/** * Create an {@code IotProvider} that uses its own {@code DirectProvider}. * @param name Name of the provider, if the value is not {@code null} then a preferences service is created. * @param iotDeviceCreator How the {@code IotDevice} is created. * * @see DirectProvider */ public IotProvider(String name, Function<Topology, IotDevice> iotDeviceCreator) { this(name, new DirectProvider(), iotDeviceCreator); }
@Override public Future<Job> submit(Topology topology) { return submit(topology, new JsonObject()); }
@Override public DirectTopology newTopology(String name) { checkName(name); return new DirectTopology(name, services); }
@Test public void testStatusCode() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/status/"; TStream<Integer> rc = HttpStreams.<Integer,Integer>requests( topology.collection(Arrays.asList(200, 404, 202)), HttpClients::noAuthentication, t-> HttpGet.METHOD_NAME, t-> url + Integer.toString(t), (t,resp) -> resp.getStatusLine().getStatusCode()); Tester tester = topology.getTester(); Condition<List<Integer>> endCondition = tester.streamContents(rc, 200, 404, 202); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }
@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); }
@Test public void testIotDevicePubSubApp() throws Exception { DirectProvider dp = new DirectProvider(); dp.getServices().addService(PublishSubscribeService.class, new ProviderPubSub()); Topology iot = dp.newTopology("IotPubSub"); IotDevicePubSub.createApplication(new EchoIotDevice(iot)); Topology app1 = dp.newTopology("App1"); Condition<List<String>> tcEcho = app1.getTester().streamContents(ecs, "A", "B", "C"); // Expect all tuples Job jIot = dp.submit(iot.topology()).get(); Job jApp = dp.submit(app1.topology()).get();
@Test public void testAppService() throws Exception { DirectProvider provider = new DirectProvider(); JsonControlService control = new JsonControlService(); provider.getServices().addService(ControlService.class, control); AppService.createAndRegister(provider, provider); IotTestApps.registerApplications(provider); JsonObject submitAppOne = newSubmitRequest("AppOne"); JsonElement crr = control.controlRequest(submitAppOne); assertTrue(crr.getAsBoolean()); }
/** * 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); }
public DirectProvider() { this.services = new ServiceContainer(); getServices().addService(ControlService.class, new JsonControlService()); }
private <T> TStream<T> createSubscriber(DirectProvider dp, String topic, Class<T> streamType) { Topology subscriber = dp.newTopology("Sub"); return PublishSubscribe.subscribe(subscriber, topic, streamType); }
@Test public void testPost() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/post"; TStream<String> stream = topology.strings(url); TStream<String> rc = HttpStreams.<String, String>requestsWithBody( stream, HttpClients::noAuthentication, t -> HttpPost.METHOD_NAME, t-> t, t-> new ByteArrayEntity(t.getBytes()), HttpResponders.inputOn200()); Tester tester = topology.getTester(); Condition<List<String>> endCondition = tester.streamContents(rc, url); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }
@Test(timeout=10000) public void testProviderServiceMultiplePublisher() throws Exception { DirectProvider dp = new DirectProvider(); dp.getServices().addService(PublishSubscribeService.class, new ProviderPubSub()); 1,2,3,82,5,432,34,99,35,456,888,263,578); // Expect all tuples Job js = dp.submit(subscribedStream.topology()).get(); Job jp1 = dp.submit(publishedStream1.topology()).get(); Job jp2 = dp.submit(publishedStream2.topology()).get(); Job jp3 = dp.submit(publishedStream3.topology()).get();
@Test //@Ignore("This test relies on an existing war in a given location ... need to refactor this") public void testAppServiceJar() throws Exception { DirectProvider provider = new DirectProvider(); JsonControlService control = new JsonControlService(); provider.getServices().addService(ControlService.class, control); AppService.createAndRegister(provider, provider); File testAppsJar = getServerJar(); assertNotNull(testAppsJar); assertTrue(testAppsJar.exists()); System.out.println("Using server jar at: " + testAppsJar.toString()); URL testAppsJarURL = testAppsJar.toURI().toURL(); JsonObject registerJar = newRegisterJarRequest(testAppsJarURL.toExternalForm()); JsonElement crr = control.controlRequest(registerJar); assertTrue(crr.getAsBoolean()); Thread.sleep(500); JsonObject submitAppTwo = newSubmitRequest("SecondJarApp"); crr = control.controlRequest(submitAppTwo); assertTrue(crr.getAsBoolean()); Thread.sleep(500); }
public DirectProvider() { this.services = new ServiceContainer(); getServices().addService(ControlService.class, new JsonControlService()); }
private <T> TStream<T> createPublisher(DirectProvider dp, String topic, Class<? super T> streamType, @SuppressWarnings("unchecked") T...values) { Topology publisher = dp.newTopology("Pub"); TStream<T> stream = publisher.of(values); PublishSubscribe.publish(stream, topic, streamType); return stream; }
@Test public void testPut() throws Exception { DirectProvider ep = new DirectProvider(); Topology topology = ep.newTopology(); String url = "http://httpbin.org/put"; TStream<String> stream = topology.strings(url); TStream<String> rc = HttpStreams.<String, String>requestsWithBody( stream, HttpClients::noAuthentication, t -> HttpPut.METHOD_NAME, t-> t, t-> new ByteArrayEntity(t.getBytes()), HttpResponders.inputOn200()); Tester tester = topology.getTester(); Condition<List<String>> endCondition = tester.streamContents(rc, url); tester.complete(ep, new JsonObject(), endCondition, 10, TimeUnit.SECONDS); assertTrue(endCondition.valid()); }
/** * Create an {@code IotProvider} that uses its own {@code DirectProvider}. * No name is assigned to the provider so a preferences service is not created. * @param iotDeviceCreator How the {@code IotDevice} is created. * * @see DirectProvider */ public IotProvider(Function<Topology, IotDevice> iotDeviceCreator) { this(null, new DirectProvider(), iotDeviceCreator); }
@Test(timeout=10000) public void testProviderServiceMultipleSubscriber() throws Exception { DirectProvider dp = new DirectProvider(); dp.getServices().addService(PublishSubscribeService.class, new ProviderPubSub()); Job js1 = dp.submit(subscribedStream1.topology()).get(); Job js2 = dp.submit(subscribedStream2.topology()).get(); Job js3 = dp.submit(subscribedStream3.topology()).get(); Thread.sleep(50); Job jp = dp.submit(publishedStream.topology()).get();
@Override public Future<Job> submit(Topology topology) { return submit(topology, new JsonObject()); }
static void startProvider(DirectProvider provider) throws InterruptedException, ExecutionException { provider.getServices().addService(ControlService.class, new JMXControlService("org.apache.edgent.test.apps.runtime", new Hashtable<>())); AppService.createAndRegister(provider, provider); JobRegistry.createAndRegister(provider.getServices()); }