use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class BatchingTxApplierTest method createTxWithId.
private CommittedTransactionRepresentation createTxWithId(long txId) {
CommittedTransactionRepresentation tx = mock(CommittedTransactionRepresentation.class);
LogEntryCommit commitEntry = mock(LogEntryCommit.class);
when(commitEntry.getTxId()).thenReturn(txId);
TransactionRepresentation txRep = mock(TransactionRepresentation.class);
when(tx.getTransactionRepresentation()).thenReturn(txRep);
when(tx.getCommitEntry()).thenReturn(commitEntry);
return tx;
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class MasterImplTest method shouldAllowCommitIfClientHoldsNoLocks.
@Test
public void shouldAllowCommitIfClientHoldsNoLocks() throws Throwable {
// Given
MasterImpl.SPI spi = mock(MasterImpl.SPI.class);
Config config = config();
DefaultConversationSPI conversationSpi = mockedConversationSpi();
ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
Client locks = mock(Client.class);
when(locks.trySharedLock(ResourceTypes.SCHEMA, ResourceTypes.schemaResource())).thenReturn(true);
when(spi.isAccessible()).thenReturn(true);
when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
when(conversationSpi.acquireClient()).thenReturn(locks);
mockEmptyResponse(spi);
MasterImpl master = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
master.start();
HandshakeResult handshake = master.handshake(1, newStoreIdForCurrentVersion()).response();
int no_lock_session = -1;
RequestContext ctx = new RequestContext(handshake.epoch(), 1, no_lock_session, 0, 0);
TransactionRepresentation tx = mock(TransactionRepresentation.class);
// When
master.commit(ctx, tx);
// Then
verify(spi).applyPreparedTransaction(tx);
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class ReplicatedTransactionCommitProcessTest method tx.
private TransactionToApply tx() {
TransactionRepresentation tx = mock(TransactionRepresentation.class);
when(tx.additionalHeader()).thenReturn(new byte[] {});
return new TransactionToApply(tx);
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LabelAndIndexUpdateBatchingIT method indexShouldIncludeNodesCreatedPreviouslyInBatch.
@Test
public void indexShouldIncludeNodesCreatedPreviouslyInBatch() throws Exception {
// GIVEN a transaction stream leading up to this issue
// perform the transactions from db-level and extract the transactions as commands
// so that they can be applied batch-wise they way we'd like to later.
// a bunch of nodes (to have the index population later on to decide to use label scan for population)
List<TransactionRepresentation> transactions;
GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
String nodeN = "our guy";
String otherNode = "just to create the tokens";
try {
try (Transaction tx = db.beginTx()) {
db.createNode(LABEL).setProperty(PROPERTY_KEY, otherNode);
for (int i = 0; i < 10_000; i++) {
db.createNode();
}
tx.success();
}
// node N
try (Transaction tx = db.beginTx()) {
db.createNode(LABEL).setProperty(PROPERTY_KEY, nodeN);
tx.success();
}
// uniqueness constraint affecting N
try (Transaction tx = db.beginTx()) {
db.schema().constraintFor(LABEL).assertPropertyIsUnique(PROPERTY_KEY).create();
tx.success();
}
transactions = extractTransactions(db);
} finally {
db.shutdown();
}
db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase();
TransactionCommitProcess commitProcess = db.getDependencyResolver().resolveDependency(TransactionCommitProcess.class);
try {
int cutoffIndex = findCutoffIndex(transactions);
commitProcess.commit(toApply(transactions.subList(0, cutoffIndex)), NULL, EXTERNAL);
// WHEN applying the two transactions (node N and the constraint) in the same batch
commitProcess.commit(toApply(transactions.subList(cutoffIndex, transactions.size())), NULL, EXTERNAL);
// THEN node N should've ended up in the index too
try (Transaction tx = db.beginTx()) {
assertNotNull("Verification node not found", // just to verify
singleOrNull(db.findNodes(LABEL, PROPERTY_KEY, otherNode)));
assertNotNull("Node N not found", singleOrNull(db.findNodes(LABEL, PROPERTY_KEY, nodeN)));
tx.success();
}
} finally {
db.shutdown();
}
}
use of org.neo4j.kernel.impl.transaction.TransactionRepresentation in project neo4j by neo4j.
the class LabelAndIndexUpdateBatchingIT method toApply.
private static TransactionToApply toApply(Collection<TransactionRepresentation> transactions) {
TransactionToApply first = null, last = null;
for (TransactionRepresentation transactionRepresentation : transactions) {
TransactionToApply transaction = new TransactionToApply(transactionRepresentation);
if (first == null) {
first = last = transaction;
} else {
last.next(transaction);
last = transaction;
}
}
return first;
}
Aggregations