private void unsubscribe() { stopPolling = true; if (!isSubscribed()) { Utils.logWarning("No subscription link to unsubscribe for service: %s", this.subscribeForServiceLink); if (completionHandler != null) { completionHandler.accept(null); } return; } Operation unSubscribe = Operation.createDelete(buildSubscribeForUri()) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { Utils.logWarning("Error unsubscribing from: %s. Error: %s", o.getUri(), Utils.toString(e)); } if (completionHandler != null) { // the completion handler should be called in both cases: error or success: completionHandler.accept(e); } }); host.stopSubscriptionService(unSubscribe, UriUtils.buildUri(host, subscriptionLink)); }
assertTrue(notification.isDelete()); assertFalse(subscriptionManager.isSubscribed());
@Test public void testNotificationSubscriptionUpdates() throws Throwable { subscribe(); state.documentSelfLink = state.documentSelfLink; doOperation(Action.PUT, state); notification = getNotification(); assertNotNull(notification); assertNotNull(notification.getResult()); assertTrue(notification.isUpdate()); updatedState = notification.getResult(); assertEquals(updatedTestId, updatedState.id); assertEquals(updatedTestValue, updatedState.image); state.id = updatedTestValue + updatedTestId; doOperation(Action.PATCH, state); notification = getNotification(); assertNotNull(notification.getResult()); assertTrue(notification.isUpdate()); updatedState = notification.getResult(); assertEquals(updatedTestValue + updatedTestId, updatedState.id); assertEquals(updatedTestValue, updatedState.image); doOperation(Action.DELETE, new ServiceDocument()); notification = getNotification(); assertNotNull(notification.getResult()); assertTrue(notification.isDelete()); assertFalse(subscriptionManager.isSubscribed()); }