use of com.github.dedis.popstellar.model.network.method.Unsubscribe in project popstellar by dedis.
the class LAONetworkManagerTest method unsubscribeSendsTheRightMessage.
@Test
public void unsubscribeSendsTheRightMessage() {
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
Unsubscribe 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(Unsubscribe.class));
// Actual test
Disposable disposable = networkManager.unsubscribe(CHANNEL).subscribe();
testScheduler.advanceTimeBy(5, TimeUnit.SECONDS);
disposable.dispose();
networkManager.dispose();
verify(connection).sendMessage(any(Unsubscribe.class));
verify(connection, atLeastOnce()).observeMessage();
verify(connection).observeConnectionEvents();
verify(connection).close();
verifyNoMoreInteractions(connection);
}
use of com.github.dedis.popstellar.model.network.method.Unsubscribe in project popstellar by dedis.
the class LAONetworkManager method unsubscribe.
@Override
public Completable unsubscribe(Channel channel) {
Log.d(TAG, "sending an unsubscribe on the channel " + channel);
Unsubscribe unsubscribe = new Unsubscribe(channel, requestCounter.incrementAndGet());
return request(unsubscribe).doOnSuccess(answer -> subscribedChannels.remove(channel)).ignoreElement();
}
Aggregations