use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.
the class PhysicalLogCommandReaderV3_0 method visitIndexDefineCommand.
private Command visitIndexDefineCommand(ReadableChannel channel) throws IOException {
readIndexCommandHeader(channel);
Map<String, Integer> indexNames = readMap(channel);
Map<String, Integer> keys = readMap(channel);
IndexDefineCommand command = new IndexDefineCommand();
command.init(indexNames, keys);
return command;
}
use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_2_4 method visitIndexDefineCommand.
private Command visitIndexDefineCommand(ReadableChannel channel) throws IOException {
readIndexCommandHeader(channel);
Map<String, Integer> indexNames = readMap(channel);
Map<String, Integer> keys = readMap(channel);
IndexDefineCommand command = new IndexDefineCommand();
command.init(indexNames, keys);
return command;
}
use of org.neo4j.kernel.impl.index.IndexDefineCommand 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());
}
use of org.neo4j.kernel.impl.index.IndexDefineCommand in project neo4j by neo4j.
the class TransactionApplierFacadeTest method testVisitIndexDefineCommand.
@Test
public void testVisitIndexDefineCommand() throws Exception {
IndexDefineCommand cmd = mock(IndexDefineCommand.class);
when(cmd.handle(any(CommandVisitor.class))).thenCallRealMethod();
// WHEN
boolean result = facade.visitIndexDefineCommand(cmd);
// THEN
InOrder inOrder = inOrder(txApplier1, txApplier2, txApplier3);
inOrder.verify(txApplier1).visitIndexDefineCommand(cmd);
inOrder.verify(txApplier2).visitIndexDefineCommand(cmd);
inOrder.verify(txApplier3).visitIndexDefineCommand(cmd);
inOrder.verifyNoMoreInteractions();
assertFalse(result);
}
Aggregations