@Test public void basicProperties() throws Exception { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); PropertyContainer graphProperties = properties(db); assertThat(graphProperties, inTx(db, not(hasProperty("test")))); Transaction tx = db.beginTx(); graphProperties.setProperty("test", "yo"); assertEquals("yo", graphProperties.getProperty("test")); tx.success(); tx.finish(); assertThat(graphProperties, inTx(db, hasProperty("test").withValue("yo"))); tx = db.beginTx(); assertNull(graphProperties.removeProperty("something non existent")); assertEquals("yo", graphProperties.removeProperty("test")); assertNull(graphProperties.getProperty("test", null)); graphProperties.setProperty("other", 10); assertEquals(10, graphProperties.getProperty("other")); graphProperties.setProperty("new", "third"); tx.success(); tx.finish(); assertThat(graphProperties, inTx(db, not(hasProperty("test")))); assertThat(graphProperties, inTx(db, hasProperty("other").withValue(10))); assertThat(getPropertyKeys(db, graphProperties), containsOnly("other", "new")); tx = db.beginTx(); graphProperties.setProperty("rollback", true); assertEquals(true, graphProperties.getProperty("rollback")); tx.finish(); assertThat(graphProperties, inTx(db, not(hasProperty("rollback")))); db.shutdown(); }
private void setSuccess(GraphDatabaseAPI graphdb, boolean success) { try (Transaction tx = graphdb.beginTx()) { Node node = graphdb.createNode(); node.setProperty("success", success); tx.success(); } }
@Test public void setManyGraphProperties() throws Exception { GraphDatabaseAPI db = (GraphDatabaseAPI) factory.newImpermanentDatabase(); Transaction tx = db.beginTx(); Object[] values = new Object[] { 10, "A string value", new float[] {1234.567F, 7654.321F}, "A rather longer string which wouldn't fit inlined #!)(&¤" }; int count = 200; for (int i = 0; i < count; i++) { properties(db).setProperty("key" + i, values[i % values.length]); } tx.success(); tx.finish(); for (int i = 0; i < count; i++) { assertThat( properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.length]))); } clearCache(db); for (int i = 0; i < count; i++) { assertThat( properties(db), inTx(db, hasProperty("key" + i).withValue(values[i % values.length]))); } db.shutdown(); }
protected Relationship[] createRelationshipChain(RelationshipType type, int length) { try (Transaction transaction = db.beginTx()) { Relationship[] relationshipChain = createRelationshipChain(db.createNode(), type, length); transaction.success(); return relationshipChain; } }
protected void assertNodeExists(long id) { try (Transaction ignore = db.beginTx()) { db.getNodeById(id); } catch (NotFoundException e) { fail("Node " + id + " should exist"); } }
public Response<IdAllocation> allocateIds(IdType idType) { IdGenerator generator = graphDb.getIdGeneratorFactory().get(idType); IdAllocation result = new IdAllocation( generator.nextIdBatch(ID_GRAB_SIZE), generator.getHighId(), generator.getDefragCount()); return ServerUtil.packResponseWithoutTransactionStream(graphDb.getStoreId(), result); }
@Override public void run(GraphDatabaseAPI graphdb) { try (Transaction ignored = graphdb.beginTx()) { for (int i = 0; i < count; i++) graphdb.index().forNodes("index" + i).get("name", i).getSingle(); } if (resume) resumeFlushThread(); }
@Override public void run(GraphDatabaseAPI graphdb) { try (Transaction tx = graphdb.beginTx()) { for (int i = 0; i < 3; i++) graphdb.index().forNodes("index" + i).add(graphdb.createNode(), "name", "" + i); tx.success(); } }
protected void assertNodeDoesntExist(long id) { try (Transaction ignore = db.beginTx()) { db.getNodeById(id); fail("Relationship " + id + " shouldn't exist"); } catch (NotFoundException e) { // Good } }
public MasterImpl(GraphDatabaseAPI db, Logging logging, Config config) { this.graphDb = db; this.msgLog = logging.getMessagesLog(getClass()); this.config = config; graphProperties = graphDb.getDependencyResolver().resolveDependency(NodeManager.class).getGraphProperties(); txManager = graphDb.getDependencyResolver().resolveDependency(TransactionManager.class); }
long createNode() { GraphDatabaseAPI graphdb = server().getDatabase().getGraph(); try (Transaction tx = graphdb.beginTx()) { Node node = graphdb.createNode(); tx.success(); return node.getId(); } }
@Override public void run(GraphDatabaseAPI graphdb) { try (Transaction ignored = graphdb.beginTx()) { // TODO: Pass a node reference around of assuming the id will be deterministically assigned, // artifact of removing the reference node, upon which this test used to depend. assertTrue((Boolean) graphdb.getNodeById(3).getProperty("success")); } }
private Set<Node> doIndexLookup(Label myLabel, Object value) { Transaction tx = db.beginTx(); Iterable<Node> iter = db.findNodesByLabelAndProperty(myLabel, NUM_BANANAS_KEY, value); Set<Node> nodes = asUniqueSet(iter); tx.success(); tx.finish(); return nodes; }
private void createARelationship(GraphDatabaseAPI db) { Transaction tx = db.beginTx(); Node node1 = db.createNode(); Node node2 = db.createNode(); node1.createRelationshipTo(node2, withName("friend")); tx.success(); tx.finish(); }
public Response<Pair<Integer, Long>> getMasterIdForCommittedTx(long txId, StoreId storeId) { XaDataSource nioneoDataSource = graphDb.getXaDataSourceManager().getNeoStoreDataSource(); try { Pair<Integer, Long> masterId = nioneoDataSource.getMasterForCommittedTx(txId); return ServerUtil.packResponseWithoutTransactionStream(graphDb.getStoreId(), masterId); } catch (IOException e) { throw new RuntimeException("Couldn't get master ID for " + txId, e); } }
private void doTransaction() { Transaction tx = db.beginTx(); try { db.createNode(); tx.success(); } finally { tx.finish(); } }
protected Node getCurrentNode() throws RemoteException, ShellException { Serializable current = shellServer.interpretVariable(shellClient.getId(), Variables.CURRENT_KEY); int nodeId = parseInt(current.toString().substring(1)); try (Transaction tx = db.beginTx()) { Node nodeById = db.getNodeById(nodeId); tx.success(); return nodeById; } }
private void updateNode(long nodeId, int value) { Transaction tx = db.beginTx(); try { Node node = db.getNodeById(nodeId); node.setProperty(NUM_BANANAS_KEY, value); tx.success(); } finally { tx.finish(); } }
private void createIndex(Label label) { Transaction tx = db.beginTx(); IndexDefinition definition = db.schema().indexFor(label).on(NUM_BANANAS_KEY).create(); tx.success(); tx.finish(); tx = db.beginTx(); db.schema().awaitIndexOnline(definition, 10, TimeUnit.SECONDS); tx.finish(); }
@Before public void before() { GraphDatabaseAPI graphDatabaseAPI = dbRule.getGraphDatabaseAPI(); this.db = graphDatabaseAPI; DependencyResolver dependencyResolver = graphDatabaseAPI.getDependencyResolver(); this.bridge = dependencyResolver.resolveDependency(ThreadToStatementContextBridge.class); graphDatabaseAPI .getDependencyResolver() .resolveDependency(Monitors.class) .addMonitorListener(indexOnlineMonitor); }
@Test public void testSetSoftRefCache() { ArrayList<CacheProvider> cacheList = new ArrayList<>(); TestGraphDatabaseFactory gdbf = new TestGraphDatabaseFactory(); cacheList.add(new SoftCacheProvider()); gdbf.setCacheProviders(cacheList); GraphDatabaseAPI db = (GraphDatabaseAPI) gdbf.newImpermanentDatabase(); assertEquals( SoftCacheProvider.NAME, db.getDependencyResolver().resolveDependency(NodeManager.class).getCacheType().getName()); }
private long createNode(Label label, int number) throws PropertyKeyNotFoundException, LabelNotFoundKernelException { Transaction tx = db.beginTx(); try { Node node = db.createNode(label); node.setProperty(NUM_BANANAS_KEY, number); tx.success(); return node.getId(); } finally { tx.finish(); } }
@Override public Response<Void> pushTransaction(RequestContext context, String resourceName, long tx) { graphDb .getTxIdGenerator() .committed( graphDb.getXaDataSourceManager().getXaDataSource(resourceName), context.getEventIdentifier(), tx, context.machineId()); return new Response<Void>( null, graphDb.getStoreId(), TransactionStream.EMPTY, ResourceReleaser.NO_OP); }
@Test public void twoUncleanInARow() throws Exception { String storeDir = new File("dir").getAbsolutePath(); EphemeralFileSystemAbstraction snapshot = produceUncleanStore(fs.get(), storeDir); snapshot = produceUncleanStore(snapshot, storeDir); snapshot = produceUncleanStore(snapshot, storeDir); GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().setFileSystem(snapshot).newImpermanentDatabase(storeDir); assertThat(properties(db), inTx(db, hasProperty("prop").withValue("Some value"))); db.shutdown(); }
protected Relationship[] createRelationshipChain( Node startingFromNode, RelationshipType type, int length) { try (Transaction tx = db.beginTx()) { Relationship[] rels = new Relationship[length]; Node firstNode = startingFromNode; for (int i = 0; i < rels.length; i++) { Node secondNode = db.createNode(); rels[i] = firstNode.createRelationshipTo(secondNode, type); firstNode = secondNode; } tx.success(); return rels; } }
private Relationship relationship(long id) throws RelationshipNotFoundException { try { return graphDb.getRelationshipById(id); } catch (NotFoundException e) { throw new RelationshipNotFoundException(); } }
private Node node(long id) throws NodeNotFoundException { try { return graphDb.getNodeById(id); } catch (NotFoundException e) { throw new NodeNotFoundException(e); } }
private void tryOnce(final GraphDatabaseAPI db, final Node node, int iterations) throws Throwable { db.getDependencyResolver().resolveDependency(Caches.class).clear(); ExecutorService executor = newCachedThreadPool(); final CountDownLatch startSignal = new CountDownLatch(1); int threads = getRuntime().availableProcessors(); final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>()); for (int i = 0; i < threads; i++) { executor.submit( new Runnable() { @Override public void run() { awaitStartSignalAndRandomTimeLonger(startSignal); Transaction transaction = db.beginTx(); try { assertEquals(relCount, count(node.getRelationships())); } catch (Throwable e) { errors.add(e); } finally { transaction.finish(); } } }); } startSignal.countDown(); executor.shutdown(); executor.awaitTermination(10, SECONDS); if (!errors.isEmpty()) { throw new MultipleCauseException( format("Exception(s) after %s iterations with %s threads", iterations, threads), errors); } }
private void flushAll() { db.getDependencyResolver() .resolveDependency(XaDataSourceManager.class) .getNeoStoreDataSource() .getNeoStore() .flushAll(); }
private int sizeOfRelationship(Relationship relationship) { try (Transaction ignore = db.beginTx()) { return getRelationshipCache() .get(relationship.getId()) .sizeOfObjectInBytesIncludingOverhead(); } }