Search in sources :

Example 16 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class EndpointChange method hashCode.

@Override
public int hashCode() {
    int result = type != null ? type.hashCode() : 0;
    result = 31 * result + (endpoint != null ? endpoint.hashCode() : 0);
    return result;
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint)

Example 17 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class DynamicConnectionTest method dynamicConnectionTest.

@Test
public void dynamicConnectionTest() throws InterruptedException {
    // serve
    PortSelectorWithinRange portSelector = new PortSelectorWithinRange(8000, 9000);
    final int serverPort1 = portSelector.acquirePort();
    final int serverPort2 = portSelector.acquirePort();
    RemoteRxServer server1 = RemoteObservable.serve(serverPort1, Observable.range(1, 100), Codecs.integer());
    server1.start();
    RemoteRxServer server2 = RemoteObservable.serve(serverPort2, Observable.range(101, 100), Codecs.integer());
    server2.start();
    Observable<Endpoint> endpointSwitch = Observable.create(new OnSubscribe<Endpoint>() {

        @Override
        public void call(Subscriber<? super Endpoint> subscriber) {
            subscriber.onNext(new Endpoint("localhost", serverPort1));
            // switch connection
            subscriber.onNext(new Endpoint("localhost", serverPort2));
        }
    });
    ConnectToObservable.Builder<Integer> config = new ConnectToObservable.Builder<Integer>().decoder(Codecs.integer());
    DynamicConnection<Integer> connection = DynamicConnection.create(config, endpointSwitch);
    MathObservable.sumInteger(connection.observable()).last().subscribe(new Action1<Integer>() {

        @Override
        public void call(Integer t1) {
            Assert.assertEquals(20100, t1.intValue());
        }
    });
    // wait for async computation
    Thread.sleep(1000);
    connection.close();
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint) Endpoint(io.mantisrx.common.network.Endpoint) Test(org.junit.Test)

Example 18 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class FixedConnectionSetTest method testMergeInWithDeltaEndpointService.

@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);
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint) List(java.util.List) LinkedList(java.util.LinkedList) Endpoint(io.mantisrx.common.network.Endpoint) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 19 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class ToDeltaEndpointInjectorTest method deltaTestWithIds.

@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);
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 20 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class FixedConnectionSetTest method testMergeInConnections.

@Test
public void testMergeInConnections() throws InterruptedException {
    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();
    EndpointInjector staticEndpoints = new EndpointInjector() {

        @Override
        public Observable<EndpointChange> deltas() {
            return Observable.create(new OnSubscribe<EndpointChange>() {

                @Override
                public void call(Subscriber<? super EndpointChange> subscriber) {
                    subscriber.onNext(new EndpointChange(EndpointChange.Type.add, new Endpoint("localhost", server1Port, "1")));
                    subscriber.onNext(new EndpointChange(EndpointChange.Type.add, new Endpoint("localhost", server2Port, "2")));
                    subscriber.onCompleted();
                }
            });
        }
    };
    FixedConnectionSet<Integer> cm = FixedConnectionSet.create(2, new ConnectToObservable.Builder<Integer>().decoder(Codecs.integer()), staticEndpoints);
    int sum = MathObservable.sumInteger(Observable.merge(cm.getObservables())).toBlocking().last();
    Assert.assertEquals(5050, sum);
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint) Endpoint(io.mantisrx.common.network.Endpoint) Test(org.junit.Test)

Aggregations

Endpoint (io.mantisrx.common.network.Endpoint)27 Test (org.junit.Test)16 Action0 (rx.functions.Action0)8 EndpointChange (io.reactivex.mantis.remote.observable.EndpointChange)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Map (java.util.Map)6 Observable (rx.Observable)6 Set (java.util.Set)5 Action1 (rx.functions.Action1)5 Func1 (rx.functions.Func1)5 Context (io.mantisrx.runtime.Context)4 StageConfig (io.mantisrx.runtime.StageConfig)4 EndpointInjector (io.reactivex.mantis.remote.observable.EndpointInjector)4 RemoteRxServer (io.reactivex.mantis.remote.observable.RemoteRxServer)4 HashMap (java.util.HashMap)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4