private void getSnapshotFilesMetadata( ResourceIterator<File> snapshot, Collection<StoreFileMetadata> targetFiles ) { snapshot.stream().map( toStoreFileMetatadata ).forEach( targetFiles::add ); }
/** * @return this result as a {@link Stream} */ @Override public Stream<Map<String,Object>> stream() { // Need to implement to disambiguate Iterable/Iterator stream return iterator().stream(); }
/** * @return this iterable as a {@link Stream} */ default Stream<T> stream() { return iterator().stream(); } }
private Set<String> getFileNames( ResourceIterator<File> files ) { return files.stream().map( File::getAbsolutePath ) .filter( this::segmentsFilePredicate ) .collect( Collectors.toSet() ); }
private List<Object> getObjectsAsList( ResourceIterator<Map<String,Object>> r, String key ) { return r.stream().map( s -> s.get( key ) ).collect( Collectors.toList() ); }
@Test public void shouldListTxLogFiles() throws Exception { assertTrue( neoStoreDataSource.listStoreFiles( true ).stream() .map( metaData -> metaData.file().getName() ) .anyMatch( fileName -> TransactionLogFiles.DEFAULT_FILENAME_FILTER.accept( null, fileName ) ) ); }
@Test public void shouldNotListTxLogFiles() throws Exception { assertTrue( neoStoreDataSource.listStoreFiles( false ).stream() .map( metaData -> metaData.file().getName() ) .noneMatch( fileName -> TransactionLogFiles.DEFAULT_FILENAME_FILTER.accept( null, fileName ) ) ); }
@Test public void shouldListNeostoreFiles() throws Exception { DatabaseLayout layout = neoStoreDataSource.getDatabaseLayout(); Set<File> expectedFiles = layout.storeFiles(); // there was no rotation expectedFiles.remove( layout.countStoreB() ); ResourceIterator<StoreFileMetadata> storeFiles = neoStoreDataSource.listStoreFiles( false ); Set<File> listedStoreFiles = storeFiles.stream() .map( StoreFileMetadata::file ) .filter( file -> !file.getName().equals( INDEX_DB_FILE_NAME ) ) .collect( Collectors.toSet() ); assertEquals( expectedFiles, listedStoreFiles ); }
Map<String,Object> expected ) List<Map<String, Object>> result = r.stream().collect( Collectors.toList() );
@Test void shouldReturnRealSnapshotIfIndexAllowsIt() throws IOException { prepareIndex(); Set<String> files = listDir( dir ); assertFalse( files.isEmpty() ); try ( ResourceIterator<File> snapshot = makeSnapshot() ) { Set<String> snapshotFiles = snapshot.stream().map( File::getName ).collect( toSet() ); assertEquals( files, snapshotFiles ); } }
@Test public void doNotListFilesFromAdditionalProviderThatRegisterTwice() throws IOException { NeoStoreFileListing neoStoreFileListing = neoStoreDataSource.getNeoStoreFileListing(); MarkerFileProvider provider = new MarkerFileProvider(); neoStoreFileListing.registerStoreFileProvider( provider ); neoStoreFileListing.registerStoreFileProvider( provider ); ResourceIterator<StoreFileMetadata> metadataResourceIterator = neoStoreFileListing.builder().build(); assertEquals( 1, metadataResourceIterator.stream().filter( metadata -> "marker".equals( metadata.file().getName() ) ).count() ); }
private void verifyLogFilesWithCustomPathListing( String path ) throws IOException { GraphDatabaseAPI graphDatabase = (GraphDatabaseAPI) new TestGraphDatabaseFactory() .newEmbeddedDatabaseBuilder( testDirectory.databaseDir( "customDb" ) ) .setConfig( GraphDatabaseSettings.logical_logs_location, path ) .newGraphDatabase(); NeoStoreDataSource dataSource = graphDatabase.getDependencyResolver().resolveDependency( NeoStoreDataSource.class ); LogFiles logFiles = graphDatabase.getDependencyResolver().resolveDependency( LogFiles.class ); assertTrue( dataSource.listStoreFiles( true ).stream() .anyMatch( metadata -> metadata.isLogFile() && logFiles.isLogFile( metadata.file() ) ) ); assertEquals( Paths.get( path ).getFileName().toString(), logFiles.logFilesDirectory().getName() ); graphDatabase.shutdown(); }
private void doubleNumericPropertyValueForAllNodesWithLabel( Index<Node> index, String numericProperty, Label label ) { try ( Transaction transaction = graphDb.beginTx() ) { ResourceIterator<Node> nodes = graphDb.findNodes( label ); nodes.stream().forEach( node -> { node.setProperty( numericProperty, (Integer) node.getProperty( numericProperty ) * 2 ); index.remove( node, numericProperty ); index.add( node, numericProperty, new ValueContext( node.getProperty( numericProperty ) ).indexNumeric() ); } ); transaction.success(); } }
private void setPropertiesAndUpdateToJunior( Index<Node> index, String nameProperty, String jobNameProperty, String[] names, String[] jobs, Label characters ) { try ( Transaction transaction = graphDb.beginTx() ) { for ( int i = 0; i < names.length; i++ ) { Node node = graphDb.createNode(characters); node.setProperty( nameProperty, names[i] ); node.setProperty( jobNameProperty, jobs[i] ); index.add( node, nameProperty, names[i] ); index.add( node, jobNameProperty, jobs[i] ); } transaction.success(); } try ( Transaction transaction = graphDb.beginTx() ) { ResourceIterator<Node> nodes = graphDb.findNodes( characters ); nodes.stream().forEach( node -> { node.setProperty( jobNameProperty, "junior " + node.getProperty( jobNameProperty ) ); index.add( node, jobNameProperty, node.getProperty( jobNameProperty ) ); } ); transaction.success(); } } }
.flatMap( l -> db.findNodes( l ).stream() ) .count();
nodes.stream().forEach( node ->
@Test public void testRenameLabelForSomeNodes() throws Exception { List<Node> nodes = db.execute("UNWIND range(0,9) as id CREATE (f:Foo {id: id, name: 'name'+id}) RETURN f").<Node>columnAs("f").stream().collect(Collectors.toList()); testCall(db, "CALL apoc.refactor.rename.label({oldName},{newName}, {nodes})", map("oldName", "Foo", "newName", "Bar", "nodes", nodes.subList(0,3)), (r) -> {}); assertEquals(new Long(3), resultNodesMatches("Bar", null)); assertEquals(new Long(7), resultNodesMatches("Foo", null)); }
@Test public void testRenamePropertyForSomeNodes() throws Exception { List<Node> nodes = db.execute("UNWIND range(0,9) as id CREATE (f:Foo {id: id, name: 'name'+id}) RETURN f").<Node>columnAs("f").stream().collect(Collectors.toList()); db.execute("Create constraint on (n:Foo) assert n.name is UNIQUE"); testCall(db, "CALL apoc.refactor.rename.nodeProperty({oldName},{newName},{nodes})", map("oldName", "name", "newName", "surname","nodes",nodes.subList(0,3)), (r) -> {}); assertEquals(new Long(3), resultNodesMatches(null, "surname")); assertEquals(new Long(7), resultNodesMatches(null, "name")); }
@Test public void testRenameNodesProperty() throws Exception { List<Node> nodes = db.execute("UNWIND range(0,9) as id CREATE (f:Foo {id: id, name: 'name'+id}) RETURN f").<Node>columnAs("f").stream().collect(Collectors.toList()); testCall(db, "CALL apoc.refactor.rename.nodeProperty({oldName},{newName})", map("oldName", "name", "newName", "surname"), (r) -> {}); assertEquals(new Long(10), resultNodesMatches(null, "surname")); assertEquals(new Long(0), resultNodesMatches(null, "name")); }
@Test public void testRunFirstColumnBugCompiled() throws Exception { ResourceIterator<Node> it = db.execute("CREATE (m:Movie {title:'MovieA'})<-[:ACTED_IN]-(p:Person {name:'PersonA'})-[:ACTED_IN]->(m2:Movie {title:'MovieB'}) RETURN m").columnAs("m"); Node movie = it.next(); it.close(); String query = "WITH {m} AS m MATCH (m)<-[:ACTED_IN]-(:Person)-[:ACTED_IN]->(rec:Movie) RETURN rec LIMIT 10"; System.out.println(db.execute("EXPLAIN "+query).getExecutionPlanDescription().toString()); ResourceIterator<Node> rec = db.execute(query, map("m",movie)).columnAs("rec"); assertEquals(1, rec.stream().count()); } @Test