private void testNodeCreationTransaction( Label label, int i ) { try ( Transaction transaction = database.beginTx() ) { Node node = database.createNode( label ); node.setProperty( "property" + i, i ); transaction.success(); } }
private File file( String localname ) { return dbRule.databaseLayout().file( localname ); } }
@Before public void doBefore() { // Delete before just to be sure deleteFileOrDirectory( new File( PATH ) ); db = dbRule.getGraphDatabaseAPI(); }
private void removeOldNodes( LongStream idRange ) { try ( Transaction transaction = database.beginTx() ) { idRange.mapToObj( id -> database.getNodeById( id ) ).forEach( Node::delete ); transaction.success(); } }
@Test public void reportNotCleanLabelIndex() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); db.resolveDependency( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File labelIndexFileCopy = databaseLayout.file( "label_index_copy" ); copyFile( databaseLayout.labelScanStore(), labelIndexFileCopy ); try ( Transaction tx = db.beginTx() ) { db.createNode( LABEL_ONE ); tx.success(); } db.shutdownAndKeepStore(); copyFile( labelIndexFileCopy, databaseLayout.labelScanStore() ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Label index was not properly shutdown and rebuild is required.") ) ); }
@Test public void shouldDisableLegacyStyleQuotingIfToldTo() throws Exception { // GIVEN String nodeId = "me"; String labelName = "Alive"; List<String> lines = new ArrayList<>(); lines.add( ":ID,name,:LABEL" ); lines.add( nodeId + "," + "\"abc\"\"def\\\"\"ghi\"" + "," + labelName ); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", data( lines.toArray( new String[lines.size()] ) ).getAbsolutePath(), "--legacy-style-quoting", "false", "--stacktrace" ); // THEN GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction tx = db.beginTx() ) { assertNotNull( db.findNode( label( labelName ), "name", "abc\"def\\\"ghi" ) ); } }
private void attemptAndFailConstraintCreation() try ( Transaction tx = db.beginTx() ) Node node1 = db.createNode( LABEL ); node1.setProperty( "prop", true ); try ( Transaction tx = db.beginTx() ) db.schema().constraintFor( LABEL ).assertPropertyIsUnique( "prop" ).create(); fail( "Should have failed with ConstraintViolationException" ); tx.success(); try ( Transaction ignore = db.beginTx() ) assertEquals( 0, Iterables.count( db.schema().getIndexes() ) );
private void createIndex( Label label, String propertyKey ) { try ( Transaction transaction = databaseRule.beginTx() ) { databaseRule.schema().indexFor( label ).on( propertyKey ).create(); transaction.success(); } try ( Transaction ignored = databaseRule.beginTx() ) { databaseRule.schema().awaitIndexesOnline( 1, TimeUnit.MINUTES ); } }
@Test public void shouldBeAbleToMakeRepeatedCallsToSetNodeProperty() throws Exception { File file = dbRule.databaseLayout().databaseDirectory(); BatchInserter inserter = BatchInserters.inserter( file, fileSystemRule.get() ); long nodeId = inserter.createNode( Collections.emptyMap() ); final Object finalValue = 87; inserter.setNodeProperty( nodeId, "a", "some property value" ); inserter.setNodeProperty( nodeId, "a", 42 ); inserter.setNodeProperty( nodeId, "a", 3.14 ); inserter.setNodeProperty( nodeId, "a", true ); inserter.setNodeProperty( nodeId, "a", finalValue ); inserter.shutdown(); GraphDatabaseService db = dbRule.getGraphDatabaseAPI(); try ( Transaction ignored = db.beginTx() ) { assertThat( db.getNodeById( nodeId ).getProperty( "a" ), equalTo( finalValue ) ); } finally { db.shutdown(); } }
@Test public void reportNotCleanNativeIndex() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File indexesCopy = databaseLayout.file( "indexesCopy" ); File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory(); copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER ); try ( Transaction tx = db.beginTx() ) { createNewNode( new Label[]{LABEL_ONE} ); tx.success(); } db.shutdownAndKeepStore(); copyRecursively( indexesCopy, indexSources ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Index was not properly shutdown and rebuild is required.") ) ); }
@Test public void mustReportMissingNode() throws Exception { // given someData(); File labelIndexFileCopy = copyLabelIndexFile(); // when try ( Transaction tx = db.beginTx() ) { db.createNode( LABEL_ONE ); tx.success(); } // and replaceLabelIndexWithCopy( labelIndexFileCopy ); db.shutdownAndKeepStore(); // then ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); }
private Map<String,Integer> getLabelsNameIdMap() { try ( Transaction ignored = embeddedDatabase.beginTx() ) { return getLabelIdsByName( COUNTRY_LABEL, COLOR_LABEL, CAR_LABEL ); } }
@Test public void mustReportExtraLabelsOnExistingNode() throws Exception { // given List<Pair<Long,Label[]>> nodesInStore = someData(); File labelIndexFileCopy = copyLabelIndexFile(); // when try ( Transaction tx = db.beginTx() ) { removeLabelFromExistingNode( nodesInStore ); tx.success(); } // and replaceLabelIndexWithCopy( labelIndexFileCopy ); db.shutdownAndKeepStore(); // then ConsistencyCheckService.Result result = fullConsistencyCheck(); assertFalse( "Expected consistency check to fail", result.isSuccessful() ); }
@Test public void reportNotCleanLabelIndexWithCorrectData() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); db.resolveDependency( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File labelIndexFileCopy = databaseLayout.file( "label_index_copy" ); copyFile( databaseLayout.labelScanStore(), labelIndexFileCopy ); db.shutdownAndKeepStore(); copyFile( labelIndexFileCopy, databaseLayout.labelScanStore() ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertTrue( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Label index was not properly shutdown and rebuild is required.") ) ); }
private SchemaState getSchemaState() { return embeddedDatabase.resolveDependency( SchemaState.class ); }
private File copyLabelIndexFile() throws IOException { DatabaseLayout databaseLayout = db.databaseLayout(); File labelIndexFileCopy = databaseLayout.file( "label_index_copy" ); db.restartDatabase( ( fs, directory ) -> fs.copyFile( databaseLayout.labelScanStore(), labelIndexFileCopy ) ); return labelIndexFileCopy; }
private void shouldPrintReferenceLinkAsPartOfErrorMessage( List<String> nodeIds, Iterator<RelationshipDataLine> relationshipDataLines, String message ) { Configuration config = Configuration.COMMAS; try { // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeData( true, config, nodeIds, TRUE ).getAbsolutePath(), "--skip-bad-relationships", "false", "--relationships", relationshipData( true, config, relationshipDataLines, TRUE, true ).getAbsolutePath() ); fail( " Should fail during import." ); } catch ( Exception e ) { // EXPECT assertTrue( suppressOutput.getErrorVoice().containsMessage( message ) ); } for ( StoreType storeType : StoreType.values() ) { if ( storeType.isRecordStore() ) { dbRule.databaseLayout().file( storeType.getDatabaseFile() ).forEach( File::delete ); } } }
@Test public void shouldRespectMaxMemorySuffixedSetting() throws Exception { // GIVEN List<String> nodeIds = nodeIds( 10 ); // WHEN importTool( "--into", dbRule.getDatabaseDirAbsolutePath(), "--nodes", nodeData( true, Configuration.COMMAS, nodeIds, TRUE ).getAbsolutePath(), "--max-memory", "100M" ); }
@Test public void reportNotCleanNativeIndexWithCorrectData() throws IOException, ConsistencyCheckIncompleteException { DatabaseLayout databaseLayout = db.databaseLayout(); someData(); resolveComponent( CheckPointer.class ).forceCheckPoint( new SimpleTriggerInfo( "forcedCheckpoint" ) ); File indexesCopy = databaseLayout.file( "indexesCopy" ); File indexSources = resolveComponent( DefaultIndexProviderMap.class ).getDefaultProvider().directoryStructure().rootDirectory(); copyRecursively( indexSources, indexesCopy, SOURCE_COPY_FILE_FILTER ); db.shutdownAndKeepStore(); copyRecursively( indexesCopy, indexSources ); ConsistencyCheckService.Result result = fullConsistencyCheck(); assertTrue( "Expected consistency check to fail", result.isSuccessful() ); assertThat( readReport( result ), hasItem( containsString("WARN : Index was not properly shutdown and rebuild is required.") ) ); }