use of com.github.dedis.popstellar.model.network.method.Subscribe in project popstellar by dedis.
the class LAONetworkManagerTest method subscribeSendsTheRightMessages.
@Test
public void subscribeSendsTheRightMessages() {
TestSchedulerProvider schedulerProvider = new TestSchedulerProvider();
TestScheduler testScheduler = schedulerProvider.getTestScheduler();
LAONetworkManager networkManager = new LAONetworkManager(laoRepository, handler, connection, JsonModule.provideGson(DataRegistryModule.provideDataRegistry()), schedulerProvider);
Answer<?> answer = args -> {
// Retrieve subscribe object
Subscribe subscribe = args.getArgument(0);
// Make sure the channel is correct
assertEquals(CHANNEL, subscribe.getChannel());
// Return a positive result
messages.onNext(new Result(subscribe.getRequestId()));
return null;
};
doAnswer(answer).when(connection).sendMessage(any(Subscribe.class));
// Actual test
Disposable disposable = networkManager.subscribe(CHANNEL).subscribe(() -> verify(connection, never()).sendMessage(any(Catchup.class)));
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
disposable.dispose();
networkManager.dispose();
verify(connection).sendMessage(any(Subscribe.class));
verify(connection).sendMessage(any(Catchup.class));
verify(connection, atLeastOnce()).observeMessage();
verify(connection).observeConnectionEvents();
verify(connection).close();
verifyNoMoreInteractions(connection);
}
use of com.github.dedis.popstellar.model.network.method.Subscribe in project popstellar by dedis.
the class LAONetworkManager method subscribe.
@Override
public Completable subscribe(Channel channel) {
Log.d(TAG, "sending a subscribe on the channel " + channel);
Subscribe subscribe = new Subscribe(channel, requestCounter.incrementAndGet());
return request(subscribe).doOnSuccess(answer -> subscribedChannels.add(channel)).doAfterSuccess(answer -> catchup(channel).subscribe()).ignoreElement();
}
use of com.github.dedis.popstellar.model.network.method.Subscribe in project popstellar by dedis.
the class ConnectionTest method sendMessageDelegatesToService.
@Test
public void sendMessageDelegatesToService() {
LAOService service = mock(LAOService.class);
BehaviorSubject<GenericMessage> messages = BehaviorSubject.create();
when(service.observeMessage()).thenReturn(messages);
BehaviorSubject<Lifecycle.State> manualState = BehaviorSubject.create();
Connection connection = new Connection(service, manualState);
Message msg = new Subscribe(Channel.ROOT, 12);
connection.sendMessage(msg);
verify(service).sendMessage(msg);
verify(service).observeMessage();
verifyNoMoreInteractions(service);
}
Aggregations