@Test
    public void testUpdateSubscriptionTwice() throws Exception
    {
        // Setup test fixture.
        final CachingPubsubPersistenceProvider provider = new CachingPubsubPersistenceProvider();
        final Node mockNode = Mockito.mock(Node.class);
        Mockito.lenient().when(mockNode.getUniqueIdentifier()).thenReturn(new Node.UniqueIdentifier("mock-service-1", "mock-node-a"));
        final JID subscriber = new JID("test-user-1", "example.org", null);
        final String subscriptionId = "test-subscription-id-" + StringUtils.randomString(7);
        final NodeSubscription firstSubscription = new NodeSubscription(mockNode, subscriber, subscriber, NodeSubscription.State.pending, subscriptionId);
        final NodeSubscription secondSubscription = new NodeSubscription(mockNode, subscriber, subscriber, NodeSubscription.State.subscribed, subscriptionId);

        // Execute system under test.
        provider.updateSubscription(mockNode, firstSubscription);
        provider.updateSubscription(mockNode, secondSubscription);

        // Verify results.
        final List<CachingPubsubPersistenceProvider.NodeOperation> pending = provider.nodesToProcess.computeIfAbsent(mockNode.getUniqueIdentifier(), id -> new ArrayList<>());
        assertEquals(1, pending.size());

        final CachingPubsubPersistenceProvider.NodeOperation nodeOperation = pending.get(0);
        assertEquals(mockNode.getUniqueIdentifier(), nodeOperation.node.getUniqueIdentifier());
        assertEquals(CachingPubsubPersistenceProvider.NodeOperation.Action.UPDATE_SUBSCRIPTION, nodeOperation.action);
        assertEquals(subscriptionId, nodeOperation.subscription.getID());
        assertEquals(NodeSubscription.State.subscribed, nodeOperation.subscription.getState()); // match the second subscription.
        assertNull(nodeOperation.affiliate);

        assertEquals(0, provider.itemsPending.size());
        assertEquals(0, provider.itemsToAdd.size());
        assertEquals(0, provider.itemsToDelete.size());
    }
Executes a test that, through {@link CachingPubsubPersistenceProvider#updateSubscription(Node, NodeSubscription)}
attempts to update the same subscription (with the same ID, same user and same node) 'twice'.

Updates of a subscription are never partial. This allows the caching provider to optimize two sequential updates.

Therefor, this test asserts that after each invocation, only one operation, corresponding to the last update, is
scheduled.
xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CachingPubsubPersistenceProviderSubscriptionOperationsTest.java