use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestProperties method intRange.
@Test
public void intRange() throws Exception {
Node node = getGraphDb().createNode();
int stride = Integer.MAX_VALUE / VALUE_RANGE_SPLIT;
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; ) {
setPropertyAndAssertIt(node, i);
i = i > 0 && Integer.MAX_VALUE - i < stride ? Integer.MAX_VALUE : i + stride;
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class TestProperties method addAndRemovePropertiesWithinOneTransaction2.
@Test
public void addAndRemovePropertiesWithinOneTransaction2() throws Exception {
Node node = getGraphDb().createNode();
node.setProperty("foo", "bar");
newTransaction();
node.setProperty("foo2", "bar");
node.removeProperty("foo");
newTransaction();
try {
node.getProperty("foo");
fail("property should not exist");
} catch (NotFoundException e) {
// good
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ManualAcquireLockTest method releaseReleaseManually.
@Test
public void releaseReleaseManually() throws Exception {
String key = "name";
Node node = getGraphDb().createNode();
tx.success();
Transaction current = tx.begin();
Lock nodeLock = current.acquireWriteLock(node);
worker.beginTx();
try {
worker.setProperty(node, key, "ksjd");
fail("Shouldn't be able to grab it");
} catch (Exception ignored) {
}
nodeLock.release();
worker.setProperty(node, key, "yo");
try {
worker.finishTx();
} catch (ExecutionException e) {
// Ok, interrupting the thread while it's waiting for a lock will lead to tx failure.
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class ManualAcquireLockTest method canOnlyReleaseOnce.
@Test
public void canOnlyReleaseOnce() throws Exception {
Node node = getGraphDb().createNode();
tx.success();
Transaction current = tx.begin();
Lock nodeLock = current.acquireWriteLock(node);
nodeLock.release();
try {
nodeLock.release();
fail("Shouldn't be able to release more than once");
} catch (IllegalStateException e) {
// Good
}
}
use of org.neo4j.graphdb.Node in project neo4j by neo4j.
the class PartialTransactionFailureIT method concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction.
@Test
public void concurrentlyCommittingTransactionsMustNotRotateOutLoggedCommandsOfFailingTransaction() throws Exception {
final ClassGuardedAdversary adversary = new ClassGuardedAdversary(new CountingAdversary(1, false), Command.RelationshipCommand.class);
adversary.disable();
File storeDir = dir.graphDbDir();
final Map<String, String> params = stringMap(GraphDatabaseSettings.pagecache_memory.name(), "8m");
final EmbeddedGraphDatabase db = new TestEmbeddedGraphDatabase(storeDir, params) {
@Override
protected void create(File storeDir, Map<String, String> params, GraphDatabaseFacadeFactory.Dependencies dependencies) {
new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {
@Override
protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {
@Override
protected FileSystemAbstraction createFileSystemAbstraction() {
return new AdversarialFileSystemAbstraction(adversary);
}
};
}
}.initFacade(storeDir, params, dependencies, this);
}
};
Node a, b, c, d;
try (Transaction tx = db.beginTx()) {
a = db.createNode();
b = db.createNode();
c = db.createNode();
d = db.createNode();
tx.success();
}
adversary.enable();
CountDownLatch latch = new CountDownLatch(1);
Thread t1 = new Thread(createRelationship(db, a, b, latch), "T1");
Thread t2 = new Thread(createRelationship(db, c, d, latch), "T2");
t1.start();
t2.start();
// Wait for both threads to get going
t1.join(10);
t2.join(10);
latch.countDown();
// Wait for the transactions to finish
t1.join(25000);
t2.join(25000);
db.shutdown();
// We should observe the store in a consistent state
EmbeddedGraphDatabase db2 = new TestEmbeddedGraphDatabase(storeDir, params);
try (Transaction tx = db2.beginTx()) {
Node x = db2.getNodeById(a.getId());
Node y = db2.getNodeById(b.getId());
Node z = db2.getNodeById(c.getId());
Node w = db2.getNodeById(d.getId());
Iterator<Relationship> itrRelX = x.getRelationships().iterator();
Iterator<Relationship> itrRelY = y.getRelationships().iterator();
Iterator<Relationship> itrRelZ = z.getRelationships().iterator();
Iterator<Relationship> itrRelW = w.getRelationships().iterator();
if (itrRelX.hasNext() != itrRelY.hasNext()) {
fail("Node x and y have inconsistent relationship counts");
} else if (itrRelX.hasNext()) {
Relationship rel = itrRelX.next();
assertEquals(rel, itrRelY.next());
assertFalse(itrRelX.hasNext());
assertFalse(itrRelY.hasNext());
}
if (itrRelZ.hasNext() != itrRelW.hasNext()) {
fail("Node z and w have inconsistent relationship counts");
} else if (itrRelZ.hasNext()) {
Relationship rel = itrRelZ.next();
assertEquals(rel, itrRelW.next());
assertFalse(itrRelZ.hasNext());
assertFalse(itrRelW.hasNext());
}
} finally {
db2.shutdown();
}
}
Aggregations