NonBlockingClientImpl extends NonBlockingClient implements FSMActions, Component, CallbackService { @Override public <T> NonBlockingClient unsubscribe(String topicPattern, String share, int ttl, CompletionListener<T> listener, T context) throws UnsubscribedException, StoppedException, IllegalArgumentException { final String methodName = "unsubscribe"; logger.entry(this, methodName, topicPattern, share, ttl, listener, context); if (topicPattern == null) { final IllegalArgumentException exception = new IllegalArgumentException("Topic pattern cannot be null"); logger.throwing(this, methodName, exception); throw exception; } if ((share != null) && share.contains(":")) { final IllegalArgumentException exception = new IllegalArgumentException("Share name cannot contain a colon (:) character"); logger.throwing(this, methodName, exception); throw exception; } if (ttl != 0) { final IllegalArgumentException exception = new IllegalArgumentException("TTL cannot be non-zero"); logger.throwing(this, methodName, exception); throw exception; } InternalUnsubscribe<T> us = new InternalUnsubscribe<>(this, topicPattern, share, true); tell(us, this); try { us.future.setListener(callbackService, listener, context); } catch (UnsubscribedException|StoppedException e) { logger.throwing(this, methodName, e); throw e; } catch (StateException e) { IllegalStateException exception = new IllegalStateException("Unexpected state exception", e); logger.ffdc(methodName, FFDCProbeId.PROBE_005, exception, this); logger.throwing(this, methodName, e); throw exception; } logger.exit(this, methodName, this); return this; } protected <T> NonBlockingClientImpl(EndpointService endpointService,
            CallbackService callbackService,
            ComponentImpl engine,
            TimerService timerService,
            GsonBuilder gsonBuilder,
            ClientOptions options,
            NonBlockingClientListener<T>listener,
            T context); <T> NonBlockingClientImpl(EndpointService endpointService,
                                     CallbackService callbackService,
                                     NetworkService networkService,
                                     TimerService timerService,
                                     GsonBuilder gsonBuilder,
                                     ClientOptions options,
                                     NonBlockingClientListener<T>listener,
                                     T context); <T> NonBlockingClientImpl(String service, ClientOptions options, NonBlockingClientListener<T> listener, T context); @Override String getId(); @Override String getService(); @Override ClientState getState(); @Override boolean send(String topic, String data, Map<String, Object> properties,
            SendOptions sendOptions, CompletionListener<T> listener, T context); @Override boolean send(String topic, ByteBuffer data, Map<String, Object> properties,
            SendOptions sendOptions, CompletionListener<T> listener, T context); @Override boolean send(String topic, Object json,
            Map<String, Object> properties, SendOptions sendOptions,
            CompletionListener<T> listener, T context); @Override boolean send(String topic, Object json, Type type,
            Map<String, Object> properties, SendOptions sendOptions,
            CompletionListener<T> listener, T context); @Override boolean sendJson(String topic, String json,
            Map<String, Object> properties, SendOptions sendOptions,
            CompletionListener<T> listener, T context); @Override NonBlockingClient start(CompletionListener<T> listener, T context); @Override void stop(CompletionListener<T> listener, T context); @Override NonBlockingClient subscribe(String topicPattern,
            SubscribeOptions subOptions, DestinationListener<T> destListener,
            CompletionListener<T> compListener, T context); @Override NonBlockingClient unsubscribe(String topicPattern, String share, int ttl, CompletionListener<T> listener, T context); @Override NonBlockingClient unsubscribe(String topicPattern, String share, CompletionListener<T> listener, T context); @Override void startTimer(); @Override void openConnection(); @Override void closeConnection(); @Override void cancelTimer(); @Override void requestEndpoint(); @Override void remakeInboundLinks(); @Override void blessEndpoint(); @Override void cleanup(); @Override void failPendingStops(); @Override void succeedPendingStops(); @Override void failPendingStarts(); @Override void succeedPendingStarts(); @Override void processQueuedActions(); @Override void eventStarting(); @Override void eventUserStopping(); @Override void eventSystemStopping(); @Override void eventStopped(); @Override void eventStarted(); @Override void eventRetrying(); @Override void eventRestarted(); @Override void breakInboundLinks(); @Override void tell(Message message, Component self); @Override void run(Runnable runnable, Object orderingCtx, Promise<Void> promise);  }
@Test public void testNullValuesIntoUnsubscribe() { StubEndpointService endpointService = new StubEndpointService(); StubCallbackService callbackService = new StubCallbackService(); MockComponent component = new MockComponent(); StubTimerService timerService = new StubTimerService(); NonBlockingClientImpl client = new NonBlockingClientImpl(endpointService, callbackService, component, timerService, null, null, null, null); client.unsubscribe("topicPattern", null, 0, null, null); client.unsubscribe("topicPattern", null, null, null); try { client.unsubscribe(null, null, 0, null, null); throw new AssertionFailedError("Null topic pattern should have thrown an exception (1)"); } catch(IllegalArgumentException e) { } try { client.unsubscribe(null, null, null, null); throw new AssertionFailedError("Null topic pattern should have thrown an exception (2)"); } catch(IllegalArgumentException e) { } }
@Test public void testInvalidShareNameIntoUnsubscribe() { StubEndpointService endpointService = new StubEndpointService(); StubCallbackService callbackService = new StubCallbackService(); MockComponent component = new MockComponent(); StubTimerService timerService = new StubTimerService(); NonBlockingClientImpl client = new NonBlockingClientImpl(endpointService, callbackService, component, timerService, null, null, null, null); client.unsubscribe("topicPattern", null, 0, null, null); client.unsubscribe("topicPattern", null, null, null); try { client.unsubscribe("topic", "sha:re", 0, null, null); throw new AssertionFailedError("Null topic pattern should have thrown an exception (1)"); } catch(IllegalArgumentException e) { } client.unsubscribe("topic", null, null, null); }
@Test public void testNonzeroTtlIntoUnsubscribe() { StubEndpointService endpointService = new StubEndpointService(); StubCallbackService callbackService = new StubCallbackService(); MockComponent component = new MockComponent(); StubTimerService timerService = new StubTimerService(); NonBlockingClientImpl client = new NonBlockingClientImpl(endpointService, callbackService, component, timerService, null, null, null, null); try { client.unsubscribe("topicPattern", null, 7, null, null); throw new AssertionFailedError("Non-zero ttl should have thrown an exception"); } catch(IllegalArgumentException e) { } }
@Test(expected=StoppedException.class) public void testUnsubscribeWhileStoppedThrowsException() { NonBlockingClientImpl client = stoppedClient(); client.unsubscribe("/kittens", null, null); }