@Test
    public void testCreateAffiliationTwice() 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.createAffiliation(mockNode, affiliate);

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

        final CachingPubsubPersistenceProvider.NodeOperation firstNodeOperation = pending.get(0);
        assertEquals(mockNode.getUniqueIdentifier(), firstNodeOperation.node.getUniqueIdentifier());
        assertEquals(CachingPubsubPersistenceProvider.NodeOperation.Action.CREATE_AFFILIATION, firstNodeOperation.action);
        assertEquals(affiliateAddress, firstNodeOperation.affiliate.getJID());
        assertEquals(affiliation, firstNodeOperation.affiliate.getAffiliation());
        assertNull(firstNodeOperation.subscription);

        final CachingPubsubPersistenceProvider.NodeOperation secondNodeOperation = pending.get(1);
        assertEquals(mockNode.getUniqueIdentifier(), secondNodeOperation.node.getUniqueIdentifier());
        assertEquals(CachingPubsubPersistenceProvider.NodeOperation.Action.CREATE_AFFILIATION, secondNodeOperation.action);
        assertEquals(affiliateAddress, secondNodeOperation.affiliate.getJID());
        assertEquals(affiliation, secondNodeOperation.affiliate.getAffiliation());
        assertNull(secondNodeOperation.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)}
attempts to create the same affiliation 'twice'.

This tests an erroneous invocation. The design of the caching provider is such that it shouldn't try to 'clean up'
such misbehavior. Instead, it should pass this through to the delegate, which is expected to generate an
appropriate error response.

Therefor, this test asserts that for each invocation, a corresponding operation is scheduled.
xmppserver/src/test/java/org/jivesoftware/openfire/pubsub/CachingPubsubPersistenceProviderAffiliationOperationsTest.java