Search in sources :

Example 1 with Commitment

use of org.neo4j.kernel.impl.transaction.log.Commitment in project neo4j by neo4j.

the class LegacyBatchIndexApplierTest method shouldOnlyCreateOneApplierPerProvider.

@Test
public void shouldOnlyCreateOneApplierPerProvider() throws Exception {
    // GIVEN
    Map<String, Integer> names = MapUtil.genericMap("first", 0, "second", 1);
    Map<String, Integer> keys = MapUtil.genericMap("key", 0);
    String applierName = "test-applier";
    Commitment commitment = mock(Commitment.class);
    when(commitment.hasLegacyIndexChanges()).thenReturn(true);
    IndexConfigStore config = newIndexConfigStore(names, applierName);
    LegacyIndexApplierLookup applierLookup = mock(LegacyIndexApplierLookup.class);
    when(applierLookup.newApplier(anyString(), anyBoolean())).thenReturn(mock(TransactionApplier.class));
    try (LegacyBatchIndexApplier applier = new LegacyBatchIndexApplier(config, applierLookup, BYPASS, INTERNAL)) {
        TransactionToApply tx = new TransactionToApply(null, 2);
        tx.commitment(commitment, 2);
        try (TransactionApplier txApplier = applier.startTx(tx)) {
            // WHEN
            IndexDefineCommand definitions = definitions(names, keys);
            txApplier.visitIndexDefineCommand(definitions);
            txApplier.visitIndexAddNodeCommand(addNodeToIndex(definitions, "first"));
            txApplier.visitIndexAddNodeCommand(addNodeToIndex(definitions, "second"));
            txApplier.visitIndexAddRelationshipCommand(addRelationshipToIndex(definitions, "second"));
        }
    }
    // THEN
    verify(applierLookup, times(1)).newApplier(eq(applierName), anyBoolean());
}
Also used : IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString) Commitment(org.neo4j.kernel.impl.transaction.log.Commitment) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IndexConfigStore (org.neo4j.kernel.impl.index.IndexConfigStore)1 IndexDefineCommand (org.neo4j.kernel.impl.index.IndexDefineCommand)1 Commitment (org.neo4j.kernel.impl.transaction.log.Commitment)1 FakeCommitment (org.neo4j.kernel.impl.transaction.log.FakeCommitment)1