//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void dumpCountsStore(org.neo4j.io.fs.FileSystemAbstraction fs, java.io.File path, java.io.PrintStream out) throws Exception //JAVA TO C# CONVERTER NOTE: Members cannot have the same name as their enclosing type: public static void DumpCountsStoreConflict(FileSystemAbstraction fs, File path, PrintStream @out) { using (JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pages = createPageCache(fs, jobScheduler), Lifespan life = new Lifespan()) { NullLogProvider logProvider = NullLogProvider.Instance; Config config = Config.defaults(); if (fs.IsDirectory(path)) { DatabaseLayout databaseLayout = DatabaseLayout.of(path); StoreFactory factory = new StoreFactory(databaseLayout, Config.defaults(), new DefaultIdGeneratorFactory(fs), pages, fs, logProvider, EmptyVersionContextSupplier.EMPTY); NeoStores neoStores = factory.OpenAllNeoStores(); SchemaStorage schemaStorage = new SchemaStorage(neoStores.SchemaStore); neoStores.Counts.accept(new DumpCountsStore(@out, neoStores, schemaStorage)); } else { VisitableCountsTracker tracker = new VisitableCountsTracker(logProvider, fs, pages, config, DatabaseLayout.of(path.ParentFile)); if (fs.FileExists(path)) { tracker.VisitFile(path, new DumpCountsStore(@out)); } else { life.Add(tracker).accept(new DumpCountsStore(@out)); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRotateCountsStoreWhenClosingTheDatabase() public virtual void ShouldRotateCountsStoreWhenClosingTheDatabase() { // GIVEN GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase(); using (Transaction tx = Db.beginTx()) { Db.createNode(_a); tx.Success(); } // WHEN Db.shutdown(); // THEN assertTrue(_fs.fileExists(AlphaStoreFile())); assertTrue(_fs.fileExists(BetaStoreFile())); using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker(_pageCache)); // a transaction for creating the label and a transaction for the node assertEquals(BASE_TX_ID + 1 + 1, store.TxId()); assertEquals(INITIAL_MINOR_VERSION, store.MinorVersion()); // one for all nodes and one for the created "A" label assertEquals(1 + 1, store.TotalEntriesStored()); assertEquals(1 + 1, AllRecords(store).Count); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateEmptyCountsTrackerStoreWhenCreatingDatabase() public virtual void ShouldCreateEmptyCountsTrackerStoreWhenCreatingDatabase() { // GIVEN GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase(); // WHEN Db.shutdown(); // THEN assertTrue(_fs.fileExists(AlphaStoreFile())); assertFalse(_fs.fileExists(BetaStoreFile())); using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker(_pageCache)); assertEquals(BASE_TX_ID, store.TxId()); assertEquals(INITIAL_MINOR_VERSION, store.MinorVersion()); assertEquals(0, store.TotalEntriesStored()); assertEquals(0, AllRecords(store).Count); } using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker(_pageCache)); assertEquals(BASE_TX_ID, store.TxId()); assertEquals(INITIAL_MINOR_VERSION, store.MinorVersion()); assertEquals(0, store.TotalEntriesStored()); assertEquals(0, AllRecords(store).Count); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRotateCountsStoreWhenRotatingLog() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRotateCountsStoreWhenRotatingLog() { // GIVEN GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase(); // WHEN doing a transaction (actually two, the label-mini-tx also counts) using (Transaction tx = Db.beginTx()) { Db.createNode(_b); tx.Success(); } // and rotating the log (which implies flushing) CheckPoint(db); // and creating another node after it using (Transaction tx = Db.beginTx()) { Db.createNode(_c); tx.Success(); } // THEN assertTrue(_fs.fileExists(AlphaStoreFile())); assertTrue(_fs.fileExists(BetaStoreFile())); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.io.pagecache.PageCache pageCache = db.getDependencyResolver().resolveDependency(org.neo4j.io.pagecache.PageCache.class); PageCache pageCache = Db.DependencyResolver.resolveDependency(typeof(PageCache)); using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker(pageCache)); // NOTE since the rotation happens before the second transaction is committed we do not see those changes // in the stats // a transaction for creating the label and a transaction for the node assertEquals(BASE_TX_ID + 1 + 1, store.TxId()); assertEquals(INITIAL_MINOR_VERSION, store.MinorVersion()); // one for all nodes and one for the created "B" label assertEquals(1 + 1, store.TotalEntriesStored()); assertEquals(1 + 1, AllRecords(store).Count); } // on the other hand the tracker should read the correct value by merging data on disk and data in memory //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final CountsTracker tracker = db.getDependencyResolver().resolveDependency(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine.class).testAccessNeoStores().getCounts(); CountsTracker tracker = Db.DependencyResolver.resolveDependency(typeof(RecordStorageEngine)).testAccessNeoStores().Counts; assertEquals(1 + 1, tracker.NodeCount(-1, newDoubleLongRegister()).readSecond()); int labelId; using (Transaction tx = Db.beginTx()) { KernelTransaction transaction = Db.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true); labelId = transaction.TokenRead().nodeLabel(_c.name()); } assertEquals(1, tracker.NodeCount(labelId, newDoubleLongRegister()).readSecond()); Db.shutdown(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToReadUpToDateValueWhileAnotherThreadIsPerformingRotation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToReadUpToDateValueWhileAnotherThreadIsPerformingRotation() { // given CountsOracle oracle = SomeData(); const int firstTransaction = 2; int secondTransaction = 3; using (Lifespan life = new Lifespan()) { CountsTracker tracker = life.Add(NewTracker()); oracle.Update(tracker, firstTransaction); tracker.Rotate(firstTransaction); } // when //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.impl.store.CountsOracle delta = new org.neo4j.kernel.impl.store.CountsOracle(); CountsOracle delta = new CountsOracle(); { CountsOracle.Node n1 = delta.Node(1); CountsOracle.Node n2 = delta.Node(1, 4); // Label 4 has not been used before... delta.Relationship(n1, 1, n2); delta.Relationship(n2, 2, n1); // relationshipType 2 has not been used before... } delta.Update(oracle); using (Lifespan life = new Lifespan()) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.Barrier_Control barrier = new org.neo4j.test.Barrier_Control(); Org.Neo4j.Test.Barrier_Control barrier = new Org.Neo4j.Test.Barrier_Control(); CountsTracker tracker = life.Add(new CountsTrackerAnonymousInnerClass(this, ResourceManager.logProvider(), ResourceManager.fileSystem(), ResourceManager.pageCache(), Config.defaults(), EmptyVersionContextSupplier.EMPTY, barrier)); Future <Void> task = Threading.execute(t => { try { delta.Update(t, secondTransaction); t.rotate(secondTransaction); } catch (IOException e) { throw new AssertionError(e); } return(null); }, tracker); // then barrier.Await(); oracle.Verify(tracker); barrier.Release(); task.get(); oracle.Verify(tracker); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPickTheUncorruptedStoreWhenTruncatingAfterTheHeader() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPickTheUncorruptedStoreWhenTruncatingAfterTheHeader() { /* * The problem was that if we were successful in writing the header but failing immediately after, we would * read 0 as counter for entry data and pick the corrupted store thinking that it was simply empty. */ Store store = CreateTestStore(); Pair <File, KeyValueStoreFile> file = store.RotationStrategy.create(EMPTY_DATA_PROVIDER, 1); Pair <File, KeyValueStoreFile> next = store.RotationStrategy.next(file.First(), Headers.HeadersBuilder().put(TX_ID, (long)42).headers(), Data((Entry)(key, value) => { key.putByte(0, ( sbyte )'f'); key.putByte(1, ( sbyte )'o'); key.putByte(2, ( sbyte )'o'); value.putInt(0, 42); })); file.Other().Dispose(); File correct = next.First(); Pair <File, KeyValueStoreFile> nextNext = store.RotationStrategy.next(correct, Headers.HeadersBuilder().put(TX_ID, (long)43).headers(), Data((key, value) => { key.putByte(0, ( sbyte )'f'); key.putByte(1, ( sbyte )'o'); key.putByte(2, ( sbyte )'o'); value.putInt(0, 42); }, (key, value) => { key.putByte(0, ( sbyte )'b'); key.putByte(1, ( sbyte )'a'); key.putByte(2, ( sbyte )'r'); value.putInt(0, 4242); })); next.Other().Dispose(); File corrupted = nextNext.First(); nextNext.Other().Dispose(); using (StoreChannel channel = _resourceManager.fileSystem().open(corrupted, OpenMode.READ_WRITE)) { channel.Truncate(16 * 4); } // then using (Lifespan life = new Lifespan()) { life.Add(store); assertNotNull(store.Get("foo")); assertEquals(42L, store.Headers().get(TX_ID).longValue()); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void addRandomBytesToLastLogFile(System.Func<sbyte> byteSource) throws java.io.IOException private void AddRandomBytesToLastLogFile(System.Func <sbyte> byteSource) { using (Lifespan lifespan = new Lifespan()) { LogFile transactionLogFile = _logFiles.LogFile; lifespan.Add(_logFiles); FlushablePositionAwareChannel logFileWriter = transactionLogFile.Writer; for (int i = 0; i < 10; i++) { logFileWriter.Put(byteSource()); } } }
private void RebuildCountsFromScratch( DatabaseLayout sourceStructure, DatabaseLayout migrationStructure, long lastTxId, ProgressReporter progressMonitor, string expectedStoreVersion, PageCache pageCache, LogProvider logProvider ) { RecordFormats recordFormats = selectForVersion( expectedStoreVersion ); IdGeneratorFactory idGeneratorFactory = new ReadOnlyIdGeneratorFactory( _fileSystem ); StoreFactory storeFactory = new StoreFactory( sourceStructure, _config, idGeneratorFactory, pageCache, _fileSystem, recordFormats, logProvider, EmptyVersionContextSupplier.EMPTY ); using ( NeoStores neoStores = storeFactory.OpenNeoStores( StoreType.NODE, StoreType.RELATIONSHIP, StoreType.LABEL_TOKEN, StoreType.RELATIONSHIP_TYPE_TOKEN ) ) { neoStores.VerifyStoreOk(); NodeStore nodeStore = neoStores.NodeStore; RelationshipStore relationshipStore = neoStores.RelationshipStore; using ( Lifespan life = new Lifespan() ) { int highLabelId = ( int ) neoStores.LabelTokenStore.HighId; int highRelationshipTypeId = ( int ) neoStores.RelationshipTypeTokenStore.HighId; CountsComputer initializer = new CountsComputer( lastTxId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId, NumberArrayFactory.auto( pageCache, migrationStructure.DatabaseDirectory(), true, [email protected]_Fields.NoMonitor ), progressMonitor ); life.Add( ( new CountsTracker( logProvider, _fileSystem, pageCache, _config, migrationStructure, EmptyVersionContextSupplier.EMPTY ) ).setInitializer( initializer ) ); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStoreCounts() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStoreCounts() { // given CountsOracle oracle = SomeData(); // when using (Lifespan life = new Lifespan()) { CountsTracker tracker = life.Add(NewTracker()); oracle.Update(tracker, 2); tracker.Rotate(2); } // then using (Lifespan life = new Lifespan()) { oracle.Verify(life.Add(NewTracker())); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPickFileWithGreatestTransactionId() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPickFileWithGreatestTransactionId() { using (Lifespan life = new Lifespan()) { Store store = life.Add(CreateTestStore()); // when for (long txId = 2; txId <= 10; txId++) { store.Updater(txId).get().close(); store.PrepareRotation(txId).rotate(); } } // then using (Lifespan life = new Lifespan()) { Store store = life.Add(CreateTestStore()); assertEquals(10L, store.Headers().get(TX_ID).longValue()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUpdateCountsOnExistingStore() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldUpdateCountsOnExistingStore() { // given CountsOracle oracle = SomeData(); int firstTx = 2; int secondTx = 3; using (Lifespan life = new Lifespan()) { CountsTracker tracker = life.Add(NewTracker()); oracle.Update(tracker, firstTx); tracker.Rotate(firstTx); oracle.Verify(tracker); // when CountsOracle delta = new CountsOracle(); { CountsOracle.Node n1 = delta.Node(1); CountsOracle.Node n2 = delta.Node(1, 4); // Label 4 has not been used before... delta.Relationship(n1, 1, n2); delta.Relationship(n2, 2, n1); // relationshipType 2 has not been used before... } delta.Update(tracker, secondTx); delta.Update(oracle); // then oracle.Verify(tracker); // when tracker.Rotate(secondTx); } // then using (Lifespan life = new Lifespan()) { oracle.Verify(life.Add(NewTracker())); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allowNonDirtyInMemoryDirtyVersionRead() public virtual void AllowNonDirtyInMemoryDirtyVersionRead() { int labelId = 1; long lastClosedTransactionId = 15L; long writeTransactionId = 13L; TransactionVersionContextSupplier versionContextSupplier = new TransactionVersionContextSupplier(); versionContextSupplier.Init(() => lastClosedTransactionId); VersionContext versionContext = versionContextSupplier.VersionContext; using (Lifespan life = new Lifespan()) { CountsTracker tracker = life.Add(NewTracker(versionContextSupplier)); using (Org.Neo4j.Kernel.Impl.Api.CountsAccessor_Updater updater = tracker.Apply(writeTransactionId).get()) { updater.IncrementNodeCount(labelId, 1); } versionContext.InitRead(); tracker.NodeCount(labelId, Registers.newDoubleLongRegister()); assertFalse(versionContext.Dirty); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static void main(String[] arguments) throws java.io.IOException public static void Main(string[] arguments) { Args args = Args.parse(arguments); long nodeCount = Settings.parseLongWithUnit(args.Get("nodes", null)); long relationshipCount = Settings.parseLongWithUnit(args.Get("relationships", null)); int labelCount = args.GetNumber("labels", 4).intValue(); int relationshipTypeCount = args.GetNumber("relationship-types", 4).intValue(); File dir = new File(args.Get(ImportTool.Options.StoreDir.key())); long randomSeed = args.GetNumber("random-seed", currentTimeMillis()).longValue(); Configuration config = Configuration.COMMAS; Extractors extractors = new Extractors(config.ArrayDelimiter()); IdType idType = IdType.valueOf(args.Get("id-type", IdType.INTEGER.name())); Groups groups = new Groups(); Header nodeHeader = ParseNodeHeader(args, idType, extractors, groups); Header relationshipHeader = ParseRelationshipHeader(args, idType, extractors, groups); Config dbConfig; string dbConfigFileName = args.Get(ImportTool.Options.DatabaseConfig.key(), null); if (!string.ReferenceEquals(dbConfigFileName, null)) { dbConfig = (new Config.Builder()).withFile(new File(dbConfigFileName)).build(); } else { dbConfig = Config.defaults(); } bool highIo = args.GetBoolean(ImportTool.Options.HighIo.key()); LogProvider logging = NullLogProvider.Instance; long pageCacheMemory = args.GetNumber("pagecache-memory", [email protected]_Fields.MaxPageCacheMemory).longValue(); [email protected] importConfig = new ConfigurationAnonymousInnerClass(args, highIo, pageCacheMemory); float factorBadNodeData = args.GetNumber("factor-bad-node-data", 0).floatValue(); float factorBadRelationshipData = args.GetNumber("factor-bad-relationship-data", 0).floatValue(); Input input = new DataGeneratorInput(nodeCount, relationshipCount, idType, Collector.EMPTY, randomSeed, 0, nodeHeader, relationshipHeader, labelCount, relationshipTypeCount, factorBadNodeData, factorBadRelationshipData); using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), Lifespan life = new Lifespan()) { BatchImporter consumer; if (args.GetBoolean("to-csv")) { consumer = new CsvOutput(dir, nodeHeader, relationshipHeader, config); } else { Console.WriteLine("Seed " + randomSeed); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.scheduler.JobScheduler jobScheduler = life.add(createScheduler()); JobScheduler jobScheduler = life.Add(createScheduler()); consumer = BatchImporterFactory.withHighestPriority().instantiate(DatabaseLayout.of(dir), fileSystem, null, importConfig, new SimpleLogService(logging, logging), defaultVisible(jobScheduler), EMPTY, dbConfig, RecordFormatSelector.selectForConfig(dbConfig, logging), NO_MONITOR, jobScheduler); ImportTool.PrintOverview(dir, Collections.emptyList(), Collections.emptyList(), importConfig, System.out); } consumer.DoImport(input); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotPickCorruptStoreFile() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotPickCorruptStoreFile() { // given Store store = CreateTestStore(); RotationStrategy rotation = store.RotationStrategy; // when File[] files = new File[10]; { Pair <File, KeyValueStoreFile> file = rotation.Create(EMPTY_DATA_PROVIDER, 1); files[0] = file.First(); for (int txId = 2, i = 1; i < Files.Length; txId <<= 1, i++) { KeyValueStoreFile old = file.Other(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int data = txId; int data = txId; file = rotation.Next(file.First(), Headers.HeadersBuilder().put(TX_ID, (long)txId).headers(), data((Entry)(key, value) => { key.putByte(0, ( sbyte )'f'); key.putByte(1, ( sbyte )'o'); key.putByte(2, ( sbyte )'o'); value.putInt(0, data); })); old.Dispose(); files[i] = file.First(); } file.Other().Dispose(); } // Corrupt the last files using (StoreChannel channel = _resourceManager.fileSystem().open(files[9], OpenMode.READ_WRITE)) { // ruin the header channel.Position(16); ByteBuffer value = ByteBuffer.allocate(16); value.put(( sbyte )0); value.flip(); channel.WriteAll(value); } using (StoreChannel channel = _resourceManager.fileSystem().open(files[8], OpenMode.READ_WRITE)) { // ruin the header channel.Position(32); ByteBuffer value = ByteBuffer.allocate(16); value.put(( sbyte )17); value.flip(); channel.WriteAll(value); } using (StoreChannel channel = _resourceManager.fileSystem().open(files[7], OpenMode.READ_WRITE)) { // ruin the header channel.Position(32 + 32 + 32 + 16); ByteBuffer value = ByteBuffer.allocate(16); value.putLong(0); value.putLong(0); value.flip(); channel.WriteAll(value); } // then using (Lifespan life = new Lifespan()) { life.Add(store); assertEquals(64L, store.Headers().get(TX_ID).longValue()); } }