//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB() public virtual void ShouldCreateACountsStoreWhenThereAreUnusedNodeRecordsInTheDB() { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("deprecation") final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) dbBuilder.newGraphDatabase(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.newGraphDatabase(); using (Transaction tx = Db.beginTx()) { Db.createNode(Label.label("A")); Db.createNode(Label.label("C")); Node node = Db.createNode(Label.label("D")); Db.createNode(); node.Delete(); tx.Success(); } long lastCommittedTransactionId = GetLastTxId(db); Db.shutdown(); RebuildCounts(lastCommittedTransactionId); using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker()); assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1, store.TxId()); assertEquals(3, store.TotalEntriesStored()); assertEquals(3, Get(store, nodeKey(-1))); assertEquals(1, Get(store, nodeKey(0))); assertEquals(1, Get(store, nodeKey(1))); assertEquals(0, Get(store, nodeKey(2))); assertEquals(0, Get(store, nodeKey(3))); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private java.util.Optional<long> getLatestTransactionLogIndex(long startTxId, org.neo4j.io.layout.DatabaseLayout databaseLayout) throws java.io.IOException private long?GetLatestTransactionLogIndex(long startTxId, DatabaseLayout databaseLayout) { if (!HasTxLogs(databaseLayout)) { return(null); } // this is not really a read-only store, because it will create an empty transaction log if there is none ReadOnlyTransactionStore txStore = new ReadOnlyTransactionStore(_pageCache, _fs, databaseLayout, _config, new Monitors()); long lastTxId = BASE_TX_ID; try { using (Lifespan ignored = new Lifespan(txStore), TransactionCursor cursor = txStore.GetTransactions(startTxId)) { while (cursor.next()) { CommittedTransactionRepresentation tx = cursor.get(); lastTxId = tx.CommitEntry.TxId; } return(lastTxId); } } catch (NoSuchTransactionException) { return(null); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeIdempotent() public virtual void ShouldBeIdempotent() { // given EphemeralFileSystemAbstraction fsa = FileSystemRule.get(); fsa.Mkdir(TestDir.directory()); StateMarshal <ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal()); DurableStateStorage <ReplicatedLockTokenState> storage = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance); using (Lifespan lifespan = new Lifespan(storage)) { ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage); MemberId memberA = member(0); MemberId memberB = member(1); stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberA, 0), 3, r => { }); // when stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberB, 1), 2, r => { }); // then assertEquals(memberA, stateMachine.CurrentToken().owner()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldHandleMultipleIdSpaces() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void ShouldHandleMultipleIdSpaces() { // GIVEN string indexName = "name"; string key = "key"; DatabaseLayout databaseLayout = _testDirectory.databaseLayout(); IndexConfigStore configStore = new IndexConfigStore(databaseLayout, _fs); configStore.Set(typeof(Node), indexName, EXACT_CONFIG); using (Lifespan lifespan = new Lifespan()) { Config dataSourceConfig = Config.defaults(LuceneDataSource.Configuration.Ephemeral, Settings.TRUE); LuceneDataSource originalDataSource = new LuceneDataSource(databaseLayout, dataSourceConfig, configStore, _fs, OperationalMode.single); LuceneDataSource dataSource = lifespan.Add(spy(originalDataSource)); using (LuceneCommandApplier applier = new LuceneCommandApplier(dataSource, false)) { // WHEN issuing a command where the index name is mapped to a certain id IndexDefineCommand definitions = definitions(ObjectIntHashMap.newWithKeysValues(indexName, 0), ObjectIntHashMap.newWithKeysValues(key, 0)); applier.VisitIndexDefineCommand(definitions); applier.VisitIndexAddNodeCommand(AddNodeToIndex(definitions, indexName, 0L)); // and then later issuing a command for that same index, but in another transaction where // the local index name id is a different one definitions = definitions(ObjectIntHashMap.newWithKeysValues(indexName, 1), ObjectIntHashMap.newWithKeysValues(key, 0)); applier.VisitIndexDefineCommand(definitions); applier.VisitIndexAddNodeCommand(AddNodeToIndex(definitions, indexName, 1L)); } // THEN both those updates should have been directed to the same index verify(dataSource, times(1)).getIndexSearcher(any(typeof(IndexIdentifier))); } }
private void CheckEmptyCountStore() { using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker()); assertEquals(BASE_TX_ID, store.TxId()); assertEquals(0, store.TotalEntriesStored()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldClearFileOnFirstUse() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldClearFileOnFirstUse() { // given EphemeralFileSystemAbstraction fsa = _fileSystemRule.get(); fsa.Mkdir(_testDir.directory()); int rotationCount = 10; DurableStateStorage <AtomicInteger> storage = new DurableStateStorage <AtomicInteger>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), rotationCount, NullLogProvider.Instance); int largestValueWritten = 0; using (Lifespan lifespan = new Lifespan(storage)) { for ( ; largestValueWritten < rotationCount * 2; largestValueWritten++) { storage.PersistStoreData(new AtomicInteger(largestValueWritten)); } } // now both files are full. We reopen, then write some more. storage = _lifeRule.add(new DurableStateStorage <>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), rotationCount, NullLogProvider.Instance)); storage.PersistStoreData(new AtomicInteger(largestValueWritten++)); storage.PersistStoreData(new AtomicInteger(largestValueWritten++)); storage.PersistStoreData(new AtomicInteger(largestValueWritten)); /* * We have written stuff in fileA but not gotten to the end (resulting in rotation). The largestValueWritten * should nevertheless be correct */ ByteBuffer forReadingBackIn = ByteBuffer.allocate(10_000); StoreChannel lastWrittenTo = fsa.Open(StateFileA(), OpenMode.READ); lastWrittenTo.read(forReadingBackIn); forReadingBackIn.flip(); AtomicInteger lastRead = null; while (true) { try { lastRead = new AtomicInteger(forReadingBackIn.Int); } catch (BufferUnderflowException) { break; } } // then assertNotNull(lastRead); assertEquals(largestValueWritten, lastRead.get()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void writePartialTx(java.io.File storeDir) throws java.io.IOException private void WritePartialTx(File storeDir) { using (PageCache pageCache = this.PageCache.getPageCache(_fs)) { LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(DatabaseLayout.of(storeDir), _fs, pageCache).build(); using (Lifespan ignored = new Lifespan(logFiles)) { LogEntryWriter writer = new LogEntryWriter(logFiles.LogFile.Writer); writer.WriteStartEntry(0, 0, 0x123456789ABCDEFL, logFiles.LogFileInformation.LastEntryId + 1, new sbyte[] { 0 }); } } }
private void AssertNoContentInNativeLabelScanStore(DatabaseLayout databaseLayout) { using (Lifespan lifespan = new Lifespan()) { NativeLabelScanStore nativeLabelScanStore = GetNativeLabelScanStore(databaseLayout, true); lifespan.Add(nativeLabelScanStore); using (LabelScanReader labelScanReader = nativeLabelScanStore.NewReader()) { int count = PrimitiveLongCollections.count(labelScanReader.NodesWithLabel(1)); assertEquals(0, count); } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void initializeNativeLabelScanStoreWithContent(org.neo4j.io.layout.DatabaseLayout databaseLayout) throws java.io.IOException private void InitializeNativeLabelScanStoreWithContent(DatabaseLayout databaseLayout) { using (Lifespan lifespan = new Lifespan()) { NativeLabelScanStore nativeLabelScanStore = GetNativeLabelScanStore(databaseLayout, false); lifespan.Add(nativeLabelScanStore); using (LabelScanWriter labelScanWriter = nativeLabelScanStore.NewWriter()) { labelScanWriter.Write(NodeLabelUpdate.labelChanges(1, new long[0], new long[] { 1 })); } nativeLabelScanStore.Force(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCreateACountStoreWhenDBContainsDenseNodes() public virtual void ShouldCreateACountStoreWhenDBContainsDenseNodes() { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("deprecation") final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) dbBuilder.setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.dense_node_threshold, "2").newGraphDatabase(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': GraphDatabaseAPI db = ( GraphDatabaseAPI )_dbBuilder.setConfig(GraphDatabaseSettings.dense_node_threshold, "2").newGraphDatabase(); using (Transaction tx = Db.beginTx()) { Node nodeA = Db.createNode(Label.label("A")); Node nodeC = Db.createNode(Label.label("C")); Node nodeD = Db.createNode(Label.label("D")); nodeA.CreateRelationshipTo(nodeA, RelationshipType.withName("TYPE1")); nodeA.CreateRelationshipTo(nodeC, RelationshipType.withName("TYPE2")); nodeA.CreateRelationshipTo(nodeD, RelationshipType.withName("TYPE3")); nodeD.CreateRelationshipTo(nodeC, RelationshipType.withName("TYPE4")); tx.Success(); } long lastCommittedTransactionId = GetLastTxId(db); Db.shutdown(); RebuildCounts(lastCommittedTransactionId); using (Lifespan life = new Lifespan()) { CountsTracker store = life.Add(CreateCountsTracker()); assertEquals(BASE_TX_ID + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1, store.TxId()); assertEquals(22, store.TotalEntriesStored()); assertEquals(3, Get(store, nodeKey(-1))); assertEquals(1, Get(store, nodeKey(0))); assertEquals(1, Get(store, nodeKey(1))); assertEquals(1, Get(store, nodeKey(2))); assertEquals(0, Get(store, nodeKey(3))); assertEquals(4, Get(store, relationshipKey(-1, -1, -1))); assertEquals(1, Get(store, relationshipKey(-1, 0, -1))); assertEquals(1, Get(store, relationshipKey(-1, 1, -1))); assertEquals(1, Get(store, relationshipKey(-1, 2, -1))); assertEquals(1, Get(store, relationshipKey(-1, 3, -1))); assertEquals(0, Get(store, relationshipKey(-1, 4, -1))); assertEquals(1, Get(store, relationshipKey(-1, 1, 1))); assertEquals(2, Get(store, relationshipKey(-1, -1, 1))); assertEquals(3, Get(store, relationshipKey(0, -1, -1))); } }
private void RebuildCounts(long lastCommittedTransactionId, ProgressReporter progressReporter) { CleanupCountsForRebuilding(); IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(_fs); StoreFactory storeFactory = new StoreFactory(_testDir.databaseLayout(), _config, idGenFactory, _pageCache, _fs, _logProvider, EmptyVersionContextSupplier.EMPTY); using (Lifespan life = new Lifespan(), NeoStores neoStores = storeFactory.OpenAllNeoStores()) { NodeStore nodeStore = neoStores.NodeStore; RelationshipStore relationshipStore = neoStores.RelationshipStore; int highLabelId = ( int )neoStores.LabelTokenStore.HighId; int highRelationshipTypeId = ( int )neoStores.RelationshipTypeTokenStore.HighId; CountsComputer countsComputer = new CountsComputer(lastCommittedTransactionId, nodeStore, relationshipStore, highLabelId, highRelationshipTypeId, [email protected]_Fields.AutoWithoutPagecache, progressReporter); CountsTracker countsTracker = CreateCountsTracker(); life.Add(countsTracker.setInitializer(countsComputer)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPersistAndRecoverState() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPersistAndRecoverState() { // given EphemeralFileSystemAbstraction fsa = FileSystemRule.get(); fsa.Mkdir(TestDir.directory()); StateMarshal <ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal()); MemberId memberA = member(0); MemberId memberB = member(1); int candidateId; DurableStateStorage <ReplicatedLockTokenState> storage = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance); using (Lifespan lifespan = new Lifespan(storage)) { ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage); // when candidateId = 0; stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberA, candidateId), 0, r => { }); candidateId = 1; stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberB, candidateId), 1, r => { }); stateMachine.Flush(); fsa.Crash(); } // then DurableStateStorage <ReplicatedLockTokenState> storage2 = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance); using (Lifespan lifespan = new Lifespan(storage2)) { ReplicatedLockTokenState initialState = storage2.InitialState; assertEquals(memberB, initialState.Get().owner()); assertEquals(candidateId, initialState.Get().id()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void populateNativeLabelScanIndexDuringMigration() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PopulateNativeLabelScanIndexDuringMigration() { Prepare34DatabaseWithNodes(); _indexMigrator.migrate(_databaseLayout, _migrationLayout, _progressReporter, StandardV3_4.STORE_VERSION, StandardV3_4.STORE_VERSION); _indexMigrator.moveMigratedFiles(_migrationLayout, _databaseLayout, StandardV2_3.STORE_VERSION, StandardV3_2.STORE_VERSION); using (Lifespan lifespan = new Lifespan()) { NativeLabelScanStore labelScanStore = GetNativeLabelScanStore(_databaseLayout, true); lifespan.Add(labelScanStore); for (int labelId = 0; labelId < 10; labelId++) { using (LabelScanReader labelScanReader = labelScanStore.NewReader()) { int nodeCount = PrimitiveLongCollections.count(labelScanReader.NodesWithLabel(labelId)); assertEquals(format("Expected to see only one node for label %d but was %d.", labelId, nodeCount), 1, nodeCount); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldBeAbleToRecoverToLatestStateAfterRotation() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldBeAbleToRecoverToLatestStateAfterRotation() { // Given int term = 0; long indexToRestoreTo; using (Lifespan lifespan = new Lifespan()) { SegmentedRaftLog log = lifespan.Add(CreateRaftLog(ROTATE_AT_SIZE_IN_BYTES)); log.Append(new RaftLogEntry(term, ReplicatedStringOfBytes(ROTATE_AT_SIZE_IN_BYTES - 40))); indexToRestoreTo = log.Append(new RaftLogEntry(term, ReplicatedInteger.valueOf(1))); } // When SegmentedRaftLog log = _life.add(CreateRaftLog(ROTATE_AT_SIZE_IN_BYTES)); // Then assertEquals(indexToRestoreTo, log.AppendIndex()); assertEquals(term, log.ReadEntryTerm(indexToRestoreTo)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void appendCheckpoint(org.neo4j.kernel.impl.transaction.log.entry.LogEntryVersion logVersion) throws java.io.IOException private void AppendCheckpoint(LogEntryVersion logVersion) { PageCache pageCache = _pageCacheRule.getPageCache(_fs); VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(); LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(_storeDirectory.databaseLayout(), _fs, pageCache).withLogEntryReader(logEntryReader).build(); LogTailScanner tailScanner = new LogTailScanner(logFiles, logEntryReader, new Monitors()); LogTailScanner.LogTailInformation tailInformation = tailScanner.TailInformation; using (Lifespan lifespan = new Lifespan(logFiles)) { FlushablePositionAwareChannel channel = logFiles.LogFile.Writer; LogPosition logPosition = tailInformation.LastCheckPoint.LogPosition; // Fake record channel.Put(logVersion.byteCode()).put(CHECK_POINT).putLong(logPosition.LogVersion).putLong(logPosition.ByteOffset); channel.PrepareForFlush().flush(); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void migrate(org.neo4j.io.layout.DatabaseLayout directoryLayout, org.neo4j.io.layout.DatabaseLayout migrationLayout, org.neo4j.kernel.impl.util.monitoring.ProgressReporter progressReporter, String versionToMigrateFrom, String versionToMigrateTo) throws java.io.IOException public override void Migrate(DatabaseLayout directoryLayout, DatabaseLayout migrationLayout, ProgressReporter progressReporter, string versionToMigrateFrom, string versionToMigrateTo) { if (IsNativeLabelScanStoreMigrationRequired(directoryLayout)) { StoreFactory storeFactory = GetStoreFactory(directoryLayout, versionToMigrateFrom); using (NeoStores neoStores = storeFactory.OpenAllNeoStores(), Lifespan lifespan = new Lifespan()) { neoStores.VerifyStoreOk(); // Remove any existing file to ensure we always do migration DeleteNativeIndexFile(migrationLayout); progressReporter.Start(neoStores.NodeStore.NumberOfIdsInUse); NativeLabelScanStore nativeLabelScanStore = GetNativeLabelScanStore(migrationLayout, progressReporter, neoStores); lifespan.Add(nativeLabelScanStore); } _nativeLabelScanStoreMigrated = true; } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public System.Nullable<long> call() throws Exception public override long?Call() { long lastCommittedTransactionId; using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), Lifespan life = new Lifespan()) { TransactionIdStore transactionIdStore = new SimpleTransactionIdStore(); TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(); LogFiles logFiles = life.Add(CreateLogFiles(transactionIdStore, fileSystem)); TransactionAppender transactionAppender = life.Add(CreateBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFiles)); ExecutorService executorService = Executors.newFixedThreadPool(_threads); try { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.concurrent.Future<?>[] handlers = new java.util.concurrent.Future[threads]; Future <object>[] handlers = new Future[_threads]; for (int i = 0; i < _threads; i++) { TransactionRepresentationFactory factory = new TransactionRepresentationFactory(); Worker task = new Worker(transactionAppender, factory, _condition); handlers[i] = executorService.submit(task); } // wait for all the workers to complete //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> handle : handlers) foreach (Future <object> handle in handlers) { handle.get(); } } finally { executorService.shutdown(); } lastCommittedTransactionId = transactionIdStore.LastCommittedTransactionId; } return(lastCommittedTransactionId); }