use of org.neo4j.kernel.ha.BranchedDataPolicy in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranchTest method shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement.
@Test
public void shouldNotBranchStoreUnlessWeHaveCopiedDownAReplacement() throws Throwable {
// Given
StoreCopyClient storeCopyClient = mock(StoreCopyClient.class);
doAnswer(invocation -> {
MoveAfterCopy moveAfterCopy = invocation.getArgumentAt(2, MoveAfterCopy.class);
moveAfterCopy.move(Stream.empty(), new File(""), new File(""));
return null;
}).when(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
PageCache pageCacheMock = mock(PageCache.class);
PagedFile pagedFileMock = mock(PagedFile.class);
when(pagedFileMock.getLastPageId()).thenReturn(1L);
when(pageCacheMock.map(any(File.class), anyInt())).thenReturn(pagedFileMock);
SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy(pageCacheMock, storeCopyClient);
URI masterUri = new URI("cluster://localhost?serverId=1");
URI me = new URI("cluster://localhost?serverId=2");
CancellationRequest cancellationRequest = CancellationRequest.NEVER_CANCELLED;
MasterClient masterClient = mock(MasterClient.class);
when(masterClient.handshake(anyLong(), any(StoreId.class))).thenThrow(new BranchedDataException(""));
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(42, 42, 42));
when(transactionIdStore.getLastCommittedTransactionId()).thenReturn(TransactionIdStore.BASE_TX_ID);
// When
BranchedDataPolicy branchPolicy = mock(BranchedDataPolicy.class);
switchToSlave.stopServicesAndHandleBranchedStore(branchPolicy, masterUri, me, cancellationRequest);
// Then
InOrder inOrder = Mockito.inOrder(storeCopyClient, branchPolicy);
inOrder.verify(storeCopyClient).copyStore(any(StoreCopyClient.StoreCopyRequester.class), any(CancellationRequest.class), any(MoveAfterCopy.class));
inOrder.verify(branchPolicy).handle(new File(""), pageCacheMock, NullLogService.getInstance());
}
use of org.neo4j.kernel.ha.BranchedDataPolicy in project neo4j by neo4j.
the class SwitchToSlaveCopyThenBranch method stopServicesAndHandleBranchedStore.
void stopServicesAndHandleBranchedStore(BranchedDataPolicy branchPolicy, URI masterUri, URI me, CancellationRequest cancellationRequest) throws Throwable {
MoveAfterCopy moveWithCopyThenBranch = (moves, fromDirectory, toDirectory) -> {
stopServices();
msgLog.debug("Branching store: " + storeDir);
branchPolicy.handle(storeDir, pageCache, logService);
msgLog.debug("Moving downloaded store from " + fromDirectory + " to " + toDirectory);
MoveAfterCopy.moveReplaceExisting().move(moves, fromDirectory, toDirectory);
msgLog.debug("Moved downloaded store from " + fromDirectory + " to " + toDirectory);
};
copyStore(masterUri, me, cancellationRequest, moveWithCopyThenBranch);
}
Aggregations