private static void performTransactions( String txPath, File storeDir ) { GraphDatabaseService database = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( GraphDatabaseSettings.logical_logs_location, txPath ) .newGraphDatabase(); for ( int i = 0; i < 10; i++ ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", "b" ); node.setProperty( "c", "d" ); transaction.success(); } } database.shutdown(); }
@Override public GraphDatabaseBuilder loadPropertiesFromFile( String fileName ) throws IllegalArgumentException { actual.loadPropertiesFromFile( fileName ); return this; }
@Override public GraphDatabaseBuilder loadPropertiesFromURL( URL url ) throws IllegalArgumentException { actual.loadPropertiesFromURL( url ); return this; }
public GraphDatabaseService newImpermanentDatabase( File storeDir ) { File absoluteDirectory = storeDir.getAbsoluteFile(); GraphDatabaseBuilder databaseBuilder = newImpermanentDatabaseBuilder( absoluteDirectory ); databaseBuilder.setConfig( GraphDatabaseSettings.active_database, absoluteDirectory.getName() ); databaseBuilder.setConfig( GraphDatabaseSettings.databases_root_path, absoluteDirectory.getParentFile().getAbsolutePath() ); return databaseBuilder.newGraphDatabase(); }
public static DbRepresentation of( File storeDir, boolean includeIndexes, Config config ) { GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ); builder.setConfig( config.getRaw() ); GraphDatabaseService db = builder.newGraphDatabase(); try { return of( db, includeIndexes ); } finally { db.shutdown(); } }
static GraphDatabaseService startDatabaseWithFormat( File storeDir, String formatName ) { return new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( record_format, formatName ) .setConfig( allow_upgrade, TRUE ).newGraphDatabase(); } }
private void createGraphDbAndKillIt() { final GraphDatabaseService db = new TestGraphDatabaseFactory() .setFileSystem( fs ) .newImpermanentDatabaseBuilder( storeDirectory.databaseDir() ) .newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { db.createNode( label( "FOO" ) ); db.createNode( label( "BAR" ) ); tx.success(); } db.shutdown(); }
byte[] arrayValue = RandomStringUtils.randomAlphanumeric( 10000 ).getBytes(); GraphDatabaseService db = new TestGraphDatabaseFactory() .setFileSystem( fs.get() ) .newImpermanentDatabaseBuilder() .setConfig( GraphDatabaseSettings.string_block_size, "1024" ) .setConfig( GraphDatabaseSettings.array_block_size, "2048" ) .newGraphDatabase(); try try ( Transaction tx = db.beginTx() ) Node node = db.createNode(); nodeId = node.getId(); node.setProperty( "string", stringValue ); node.setProperty( "array", arrayValue ); tx.success(); try ( Transaction tx = db.beginTx() ) Node node = db.getNodeById( nodeId ); assertEquals( stringValue, node.getProperty( "string" ) ); assertArrayEquals( arrayValue, (byte[]) node.getProperty( "array" ) ); tx.success();
@Test public void databaseShutdownDuringConstantCheckPointing() throws InterruptedException { GraphDatabaseService db = builder .setConfig( GraphDatabaseSettings.check_point_interval_time, 0 + "ms" ) .setConfig( GraphDatabaseSettings.check_point_interval_tx, "1" ) .setConfig( GraphDatabaseSettings.logical_log_rotation_threshold, "1g" ) .newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { db.createNode(); tx.success(); } Thread.sleep( 10 ); db.shutdown(); }
private StoreAccess createStoreWithOneHighDegreeNodeAndSeveralDegreeTwoNodes( int nDegreeTwoNodes ) File storeDirectory = testDirectory.databaseDir(); GraphDatabaseService database = new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( storeDirectory ) .setConfig( GraphDatabaseSettings.record_format, getRecordFormatName() ) .setConfig( "dbms.backup.enabled", "false" ) .newGraphDatabase(); try ( Transaction transaction = database.beginTx() ) Node denseNode = database.createNode(); for ( int i = 0; i < nDegreeTwoNodes; i++ ) Node degreeTwoNode = database.createNode(); Node leafNode = database.createNode(); if ( i % 2 == 0 ) denseNode.createRelationshipTo( degreeTwoNode, TestRelationshipType.CONNECTED ); degreeTwoNode.createRelationshipTo( denseNode, TestRelationshipType.CONNECTED ); degreeTwoNode.createRelationshipTo( leafNode, TestRelationshipType.CONNECTED ); transaction.success();
@SuppressWarnings("deprecation") @Before public void setUp() throws IOException { db = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { michaelaNode = db.createNode(); andreasNode = db.createNode(); johanNode = db.createNode(); andreasNode.setProperty( "name", "Andreas" ); johanNode.setProperty( "name", "Johan" ); michaelaNode.setProperty( "name", "Michaela" ); index( andreasNode ); index( johanNode ); index( michaelaNode ); tx.success(); } }
@Test void failToDowngradeFormatWheUpgradeAllowed() { GraphDatabaseService database = startDatabaseWithFormatUnspecifiedUpgrade( storeDir, StandardV3_4.NAME ); try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode(); node.setProperty( "a", "b" ); transaction.success(); } database.shutdown(); Throwable throwable = assertThrows( Throwable.class, () -> new GraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir ) .setConfig( record_format, StandardV3_2.NAME ) .setConfig( allow_upgrade, Settings.TRUE ).newGraphDatabase() ); assertSame( StoreUpgrader.AttemptedDowngradeException.class, Exceptions.rootCause( throwable ).getClass() ); }
private void removeReferenceNodeAndFinalizeKeyIndices() { GraphDatabaseService rawGraphDB = null; try { GraphDatabaseBuilder builder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(this.rawGraph.getStoreDir()); if (this.vertexIndexKeys.size() > 0) builder.setConfig(GraphDatabaseSettings.node_keys_indexable, vertexIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.node_auto_indexing, GraphDatabaseSetting.TRUE); if (this.edgeIndexKeys.size() > 0) builder.setConfig(GraphDatabaseSettings.relationship_keys_indexable, edgeIndexKeys.toString().replace("[", "").replace("]", "")).setConfig(GraphDatabaseSettings.relationship_auto_indexing, GraphDatabaseSetting.TRUE); rawGraphDB = builder.newGraphDatabase(); Transaction tx = rawGraphDB.beginTx(); try { rawGraphDB.getReferenceNode().delete(); tx.success(); } catch (Exception e) { tx.failure(); } finally { tx.finish(); } GlobalGraphOperations graphOperations = GlobalGraphOperations.at(rawGraphDB); if (this.vertexIndexKeys.size() > 0) populateKeyIndices(rawGraphDB, rawGraphDB.index().getNodeAutoIndexer(), graphOperations.getAllNodes(), Vertex.class); if (this.edgeIndexKeys.size() > 0) populateKeyIndices(rawGraphDB, rawGraphDB.index().getRelationshipAutoIndexer(), graphOperations.getAllRelationships(), Edge.class); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } finally { if (rawGraphDB != null) rawGraphDB.shutdown(); } }
adversary.disable(); File databaseDir = directory.databaseDir(); GraphDatabaseService db = AdversarialPageCacheGraphDatabaseFactory.create( fileSystemRule.get(), adversary ) .newEmbeddedDatabaseBuilder( databaseDir ) .newGraphDatabase(); try try ( Transaction tx = db.beginTx() ) db.schema().constraintFor( label ).assertPropertyIsUnique( property ).create(); tx.success(); try ( Transaction tx = db.beginTx() ) Node node = db.createNode( label ); node.setProperty( property, "B" ); db.getRelationshipById( relationshipId ).delete(); // this should fail because of the adversary tx.success(); adversary.enable(); assertNotNull( db.getRelationshipById( relationshipId ) ); tx.success();
private GraphDatabaseService graphDatabaseService( Config config ) { TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory(); factory.setFileSystem( fileSystemRule.get() ); return factory.newImpermanentDatabaseBuilder( storeDir.databaseDir() ) // Shouldn't be necessary to set dense node threshold since it's a stick config .setConfig( config.getRaw() ) .newGraphDatabase(); }
private void dropIndexes() { GraphDatabaseService db = new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( directory.databaseDir() ) .setConfig( GraphDatabaseSettings.pagecache_memory, "8m" ) .newGraphDatabase(); try ( Transaction tx = db.beginTx() ) { for ( IndexDefinition index : db.schema().getIndexes() ) { index.drop(); } tx.success(); } finally { db.shutdown(); } }
public static void main( String[] args ) throws IOException final GraphDatabaseService db = new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( path ) .newGraphDatabase(); final Index<Node> index = getIndex( db ); final String[] keys = new String[]{"apoc", "zion", "morpheus"}; while ( true ) try ( Transaction tx = db.beginTx() ) String value = values[i1 % values.length] + i1; Node node = db.createNode(); node.setProperty( key, value ); index.add( node, key, value ); tx.success();
private void prepareDbWithDeletedRelationshipPartOfTheChain() GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( testDirectory.databaseDir() ) .setConfig( GraphDatabaseSettings.record_format, getRecordFormatName() ) .setConfig( "dbms.backup.enabled", "false" ) .newGraphDatabase(); try node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); node1.createRelationshipTo( node2, relationshipType ); tx.success();
.newEmbeddedDatabaseBuilder( testDir.databaseDir() ) .newGraphDatabase(); try ( Transaction tx = db.beginTx() ) db.createNode(); await( txCommitLatch ); tx.success(); db.shutdown();
@Test public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception final GraphDatabaseAPI db = (GraphDatabaseAPI) new TestGraphDatabaseFactory() .setFileSystem( fs.get() ).newImpermanentDatabaseBuilder( testDir.databaseDir() ) .setConfig( GraphDatabaseSettings.record_id_batch_size, "1" ) .newGraphDatabase(); List<Long> deletedNodeIds = produceNonCleanDefraggedStringStore( db ); Map<IdType,Long> highIdsBeforeCrash = getHighIds( db ); if ( snapshotChecksum != checksumBefore ) try ( OutputStream out = new FileOutputStream( testDir.file( "snapshot.zip" ) ) ) try ( OutputStream out = new FileOutputStream( testDir.file( "fs.zip" ) ) ) .setFileSystem( snapshot ) .newImpermanentDatabaseBuilder( testDir.databaseDir() ) .setConfig( GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE ) .newGraphDatabase(); Map<IdType,Long> highIdsAfterCrash = getHighIds( newDb ); assertEquals( highIdsBeforeCrash, highIdsAfterCrash ); relCount += Iterables.count( node.getRelationships( Direction.OUTGOING ) );