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;
}
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();
}
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);
}
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);
}
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);
}
Aggregations