@Test
    public void testDeleteAffiliationDoesNotVoidNewerCreate2() 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 affiliateAddress = new JID("test-user-1", "example.org", null);
        final NodeAffiliate affiliate = new NodeAffiliate(mockNode, affiliateAddress);
        final NodeAffiliate.Affiliation affiliation = NodeAffiliate.Affiliation.publisher;
        affiliate.setAffiliation(affiliation);

        // Execute system under test.
        provider.createAffiliation(mockNode, affiliate);
        provider.removeAffiliation(mockNode, affiliate);
        provider.createAffiliation(mockNode, affiliate);

        // 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.CREATE_AFFILIATION, nodeOperation.action);
        assertEquals(affiliateAddress, nodeOperation.affiliate.getJID());
        assertEquals(affiliation, nodeOperation.affiliate.getAffiliation());
        assertNull(nodeOperation.subscription);

        assertEquals(0, provider.itemsPending.size());
        assertEquals(0, provider.itemsToAdd.size());
        assertEquals(0, provider.itemsToDelete.size());
    }
Executes a test that, through {@link CachingPubsubPersistenceProvider#createAffiliation(Node, NodeAffiliate)},
{@link CachingPubsubPersistenceProvider#removeAffiliation(Node, NodeAffiliate)} and
{@link CachingPubsubPersistenceProvider#createAffiliation(Node, NodeAffiliate)}
creates, then removes and then recreate an affiliation again.

The caching provider can optimize the first two operations, where the 'net effect' of them is to have no operation.

Therefor, this test asserts that after all invocations, only one operation that represents the last invocation,
is scheduled.
xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CachingPubsubPersistenceProviderAffiliationOperationsTest.java