assertEquals(PubSubException.ClientAlreadySubscribedException.class, ConcurrencyUtils.take(callback1.queue)
.right().getClass());
// trying to subscribe again should throw an error
WriteRecordingChannel dupChannel = new WriteRecordingChannel();
sh.handleRequestAtOwner(pubSubRequestPrototype, dupChannel);
assertEquals(StatusCode.TOPIC_BUSY, ((PubSubResponse) dupChannel.getMessagesWritten().get(0)).getStatusCode());
// after disconnecting the channel, subscribe should work again
subChannelMgr.channelDisconnected(channel);
dupChannel = new WriteRecordingChannel();
sh.handleRequestAtOwner(pubSubRequestPrototype, dupChannel);
assertEquals(StatusCode.SUCCESS, ((PubSubResponse) dupChannel.getMessagesWritten().get(0)).getStatusCode());
// test unsubscribe
channel = new WriteRecordingChannel();
ush.handleRequestAtOwner(pubSubRequestPrototype, channel);
assertEquals(StatusCode.MALFORMED_REQUEST, ((PubSubResponse) channel.getMessagesWritten().get(0))
.getStatusCode());
PubSubRequest unsubRequest = PubSubRequest.newBuilder(pubSubRequestPrototype).setUnsubscribeRequest(
UnsubscribeRequest.newBuilder().setSubscriberId(subscriberId)).build();
channel = new WriteRecordingChannel();
dm.lastRequest.clear();
ush.handleRequestAtOwner(unsubRequest, channel);
assertEquals(StatusCode.SUCCESS, ((PubSubResponse) channel.getMessagesWritten().get(0)).getStatusCode());