Search in sources :

Example 1 with HighAvailabilityMemberListener

use of org.neo4j.kernel.ha.cluster.HighAvailabilityMemberListener in project neo4j by neo4j.

the class UpdatePullingTransactionObligationFulfillerTest method shouldUpdateTransactionIdStoreCorrectly.

@Test
public void shouldUpdateTransactionIdStoreCorrectly() throws Throwable {
    // Given
    TransactionIdStore store1 = mock(TransactionIdStore.class);
    TransactionIdStore store2 = mock(TransactionIdStore.class);
    @SuppressWarnings("unchecked") Supplier<TransactionIdStore> supplier = mock(Supplier.class);
    when(supplier.get()).thenReturn(store1, store2);
    doAnswer(invocation -> {
        ((HighAvailabilityMemberListener) invocation.getArguments()[0]).slaveIsAvailable(new HighAvailabilityMemberChangeEvent(null, null, serverId, null));
        return null;
    }).when(machine).addHighAvailabilityMemberListener(any(HighAvailabilityMemberListener.class));
    doAnswer(invocation -> {
        ((HighAvailabilityMemberListener) invocation.getArguments()[0]).instanceStops(new HighAvailabilityMemberChangeEvent(null, null, serverId, null));
        return null;
    }).when(machine).removeHighAvailabilityMemberListener(any(HighAvailabilityMemberListener.class));
    UpdatePullingTransactionObligationFulfiller fulfiller = new UpdatePullingTransactionObligationFulfiller(updatePuller, machine, serverId, supplier);
    // When
    fulfiller.start();
    fulfiller.fulfill(1);
    fulfiller.stop();
    fulfiller.fulfill(2);
    fulfiller.start();
    fulfiller.fulfill(3);
    fulfiller.stop();
    fulfiller.fulfill(4);
    // Then
    verify(store1, times(1)).getLastClosedTransactionId();
    verify(store2, times(1)).getLastClosedTransactionId();
}
Also used : HighAvailabilityMemberListener(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberListener) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) HighAvailabilityMemberChangeEvent(org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 HighAvailabilityMemberChangeEvent (org.neo4j.kernel.ha.cluster.HighAvailabilityMemberChangeEvent)1 HighAvailabilityMemberListener (org.neo4j.kernel.ha.cluster.HighAvailabilityMemberListener)1 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)1