Java Code Examples for rx.subjects.ReplaySubject#onNext()
The following examples show how to use
rx.subjects.ReplaySubject#onNext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IngressPolicies.java From mantis with Apache License 2.0 | 5 votes |
public static IngressPolicy allowOnlyLocalhost() { ReplaySubject<Set<String>> subject = ReplaySubject.create(); Set<String> list = new HashSet<String>(); list.add("127.0.0.1"); subject.onNext(list); return new InetAddressWhiteListIngressPolicy(subject); }
Example 2
Source File: FixedConnectionSetTest.java From mantis with Apache License 2.0 | 5 votes |
@Test public void testMergeInWithDeltaEndpointService() { PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000); final int server1Port = portSelector.acquirePort(); final int server2Port = portSelector.acquirePort(); // setup servers RemoteRxServer server1 = RemoteObservable.serve(server1Port, Observable.range(1, 50), Codecs.integer()); RemoteRxServer server2 = RemoteObservable.serve(server2Port, Observable.range(51, 50), Codecs.integer()); server1.start(); server2.start(); ReplaySubject<List<Endpoint>> subject = ReplaySubject.create(); List<Endpoint> endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", server1Port)); endpoints.add(new Endpoint("localhost", server2Port)); subject.onNext(endpoints); FixedConnectionSet<Integer> cm = FixedConnectionSet.create(2, new ConnectToObservable.Builder<Integer>() .decoder(Codecs.integer()), new ToDeltaEndpointInjector(subject)); int sum = MathObservable.sumInteger(Observable.merge(cm.getObservables())) .toBlocking() .last(); Assert.assertEquals(5050, sum); }
Example 3
Source File: RemoteObservableTest.java From mantis with Apache License 2.0 | 5 votes |
@Test public void testServedMergedObservables() { // setup Observable<Integer> os1 = Observable.range(0, 101); Observable<Integer> os2 = Observable.range(100, 101); ReplaySubject<Observable<Integer>> subject = ReplaySubject.create(); subject.onNext(os1); subject.onNext(os2); subject.onCompleted(); PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000); int port = portSelector.acquirePort(); RemoteRxServer server = new RemoteRxServer.Builder() .port(port) .addObservable(new ServeObservable.Builder<Integer>() .encoder(Codecs.integer()) .observable(Observable.merge(subject)) .build()) .build(); // serve server.start(); // connect Observable<Integer> oc = RemoteObservable.connect("localhost", port, Codecs.integer()); // assert MathObservable.sumInteger(oc).toBlocking().forEach(new Action1<Integer>() { @Override public void call(Integer t1) { Assert.assertEquals(20200, t1.intValue()); // sum of number 0-200 } }); }
Example 4
Source File: RemoteObservableTest.java From mantis with Apache License 2.0 | 5 votes |
@Test public void testServedMergedObservablesAddAfterServe() { // setup Observable<Integer> os1 = Observable.range(0, 100); Observable<Integer> os2 = Observable.range(100, 100); ReplaySubject<Observable<Integer>> subject = ReplaySubject.create(); subject.onNext(os1); subject.onNext(os2); // serve PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000); int serverPort = portSelector.acquirePort(); RemoteRxServer server = new RemoteRxServer.Builder() .port(serverPort) .addObservable(new ServeObservable.Builder<Integer>() .encoder(Codecs.integer()) .observable(Observable.merge(subject)) .build()) .build(); server.start(); // add after serve Observable<Integer> os3 = Observable.range(200, 101); subject.onNext(os3); subject.onCompleted(); // connect Observable<Integer> oc = RemoteObservable.connect("localhost", serverPort, Codecs.integer()); // assert MathObservable.sumInteger(oc).toBlocking().forEach(new Action1<Integer>() { @Override public void call(Integer t1) { Assert.assertEquals(45150, t1.intValue()); // sum of number 0-200 } }); }
Example 5
Source File: DynamicConnectionSetTest.java From mantis with Apache License 2.0 | 5 votes |
@Test public void testMergeInWithDeltaEndpointService() { PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000); final int server1Port = portSelector.acquirePort(); final int server2Port = portSelector.acquirePort(); // setup servers RemoteRxServer server1 = RemoteObservable.serve(server1Port, Observable.range(1, 50), Codecs.integer()); RemoteRxServer server2 = RemoteObservable.serve(server2Port, Observable.range(51, 50), Codecs.integer()); server1.start(); server2.start(); ReplaySubject<List<Endpoint>> subject = ReplaySubject.create(); List<Endpoint> endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", server1Port)); endpoints.add(new Endpoint("localhost", server2Port)); subject.onNext(endpoints); subject.onCompleted(); DynamicConnectionSet<Integer> cm = DynamicConnectionSet.create(new ConnectToObservable.Builder<Integer>() .decoder(Codecs.integer())); cm.setEndpointInjector(new ToDeltaEndpointInjector(subject)); int sum = MathObservable.sumInteger(Observable.merge(cm.observables())) .toBlocking() .last(); Assert.assertEquals(5050, sum); }
Example 6
Source File: ToDeltaEndpointInjectorTest.java From mantis with Apache License 2.0 | 4 votes |
@Test public void deltaTest() { ReplaySubject<List<Endpoint>> subject = ReplaySubject.create(); ToDeltaEndpointInjector service = new ToDeltaEndpointInjector(subject); // 1 add endpoints List<Endpoint> endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234)); endpoints.add(new Endpoint("localhost", 2468)); subject.onNext(endpoints); // 2 remove endpoint by leaving out second endpoint endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234)); subject.onNext(endpoints); // 3 remove other endpoints = new LinkedList<Endpoint>(); subject.onNext(endpoints); // 4 add back endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234)); endpoints.add(new Endpoint("localhost", 2468)); subject.onNext(endpoints); subject.onCompleted(); BlockingObservable<EndpointChange> be = service.deltas().toBlocking(); // check for two adds Iterator<EndpointChange> iter = be.getIterator(); Assert.assertTrue(iter.hasNext()); EndpointChange ce1 = iter.next(); Assert.assertEquals(ce1.getEndpoint().getSlotId(), "localhost:1234"); Assert.assertEquals(ce1.getType(), EndpointChange.Type.add); EndpointChange ce2 = iter.next(); Assert.assertEquals(ce2.getEndpoint().getSlotId(), "localhost:2468"); Assert.assertEquals(ce2.getType(), EndpointChange.Type.add); // check for complete EndpointChange ce3 = iter.next(); Assert.assertEquals(ce3.getEndpoint().getSlotId(), "localhost:2468"); Assert.assertEquals(ce3.getType(), EndpointChange.Type.complete); // check for complete EndpointChange ce4 = iter.next(); Assert.assertEquals(ce4.getEndpoint().getSlotId(), "localhost:1234"); Assert.assertEquals(ce4.getType(), EndpointChange.Type.complete); // check for add EndpointChange ce5 = iter.next(); Assert.assertEquals(ce5.getEndpoint().getSlotId(), "localhost:1234"); Assert.assertEquals(ce5.getType(), EndpointChange.Type.add); EndpointChange ce6 = iter.next(); Assert.assertEquals(ce6.getEndpoint().getSlotId(), "localhost:2468"); Assert.assertEquals(ce6.getType(), EndpointChange.Type.add); }
Example 7
Source File: ToDeltaEndpointInjectorTest.java From mantis with Apache License 2.0 | 4 votes |
@Test public void deltaTestWithIds() { ReplaySubject<List<Endpoint>> subject = ReplaySubject.create(); ToDeltaEndpointInjector service = new ToDeltaEndpointInjector(subject); // 1. add endpoints List<Endpoint> endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234, "abc")); endpoints.add(new Endpoint("localhost", 2468, "xyz")); subject.onNext(endpoints); // 2. nothing changes endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234, "abc")); endpoints.add(new Endpoint("localhost", 2468, "xyz")); subject.onNext(endpoints); // 3. remove endpoint by leaving out second endpoint endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234, "abc")); subject.onNext(endpoints); // 4. remove all endpoints = new LinkedList<Endpoint>(); subject.onNext(endpoints); // 5. add back endpoints = new LinkedList<Endpoint>(); endpoints.add(new Endpoint("localhost", 1234, "abc")); endpoints.add(new Endpoint("localhost", 2468, "xyz")); subject.onNext(endpoints); subject.onCompleted(); BlockingObservable<EndpointChange> be = service.deltas().toBlocking(); Iterator<EndpointChange> iter = be.getIterator(); Assert.assertTrue(iter.hasNext()); EndpointChange ce2 = iter.next(); Assert.assertEquals(ce2.getEndpoint().getSlotId(), "xyz"); Assert.assertEquals(ce2.getType(), EndpointChange.Type.add); EndpointChange ce1 = iter.next(); Assert.assertEquals(ce1.getEndpoint().getSlotId(), "abc"); Assert.assertEquals(ce1.getType(), EndpointChange.Type.add); EndpointChange ce3 = iter.next(); Assert.assertEquals(ce3.getEndpoint().getSlotId(), "xyz"); Assert.assertEquals(ce3.getType(), EndpointChange.Type.complete); EndpointChange ce4 = iter.next(); Assert.assertEquals(ce4.getEndpoint().getSlotId(), "abc"); Assert.assertEquals(ce4.getType(), EndpointChange.Type.complete); EndpointChange ce6 = iter.next(); Assert.assertEquals(ce6.getEndpoint().getSlotId(), "xyz"); Assert.assertEquals(ce6.getType(), EndpointChange.Type.add); EndpointChange ce5 = iter.next(); Assert.assertEquals(ce5.getEndpoint().getSlotId(), "abc"); Assert.assertEquals(ce5.getType(), EndpointChange.Type.add); }
Example 8
Source File: RemoteObservableTest.java From mantis with Apache License 2.0 | 4 votes |
@Test public void testServedMergedObservablesAddAfterConnect() { // setup Observable<Integer> os1 = Observable.range(0, 100); Observable<Integer> os2 = Observable.range(100, 100); ReplaySubject<Observable<Integer>> subject = ReplaySubject.create(); subject.onNext(os1); subject.onNext(os2); // serve PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000); int serverPort = portSelector.acquirePort(); RemoteRxServer server = new RemoteRxServer.Builder() .port(serverPort) .addObservable(new ServeObservable.Builder<Integer>() .encoder(Codecs.integer()) .observable(Observable.merge(subject)) .build()) .build(); server.start(); // add after serve Observable<Integer> os3 = Observable.range(200, 100); subject.onNext(os3); // connect Observable<Integer> oc = RemoteObservable.connect("localhost", serverPort, Codecs.integer()); // add after connect Observable<Integer> os4 = Observable.range(300, 101); subject.onNext(os4); subject.onCompleted(); // assert MathObservable.sumInteger(oc).toBlocking().forEach(new Action1<Integer>() { @Override public void call(Integer t1) { Assert.assertEquals(80200, t1.intValue()); // sum of number 0-200 } }); }