//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testIt() public virtual void TestIt() { int sizePerJump = 1000; IdGeneratorFactory factory = new JumpingIdGeneratorFactory(sizePerJump); IdGenerator generator = factory.Get(IdType.NODE); for (int i = 0; i < sizePerJump / 2; i++) { assertEquals(i, generator.NextId()); } for (int i = 0; i < sizePerJump - 1; i++) { long expected = 0x100000000L - sizePerJump / 2 + i; if (expected >= 0xFFFFFFFFL) { expected++; } assertEquals(expected, generator.NextId()); } for (int i = 0; i < sizePerJump; i++) { assertEquals(0x200000000L - sizePerJump / 2 + i, generator.NextId()); } for (int i = 0; i < sizePerJump; i++) { assertEquals(0x300000000L - sizePerJump / 2 + i, generator.NextId()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testOffsetFileChannel() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void TestOffsetFileChannel() { using (JumpingFileSystemAbstraction offsetFileSystem = new JumpingFileSystemAbstraction(10)) { File fileName = new File("target/var/neostore.nodestore.db"); offsetFileSystem.DeleteFile(fileName); offsetFileSystem.Mkdirs(fileName.ParentFile); IdGenerator idGenerator = (new JumpingIdGeneratorFactory(10)).Get(IdType.NODE); using (JumpingFileChannel channel = ( JumpingFileChannel )offsetFileSystem.Open(fileName, OpenMode.READ_WRITE)) { for (int i = 0; i < 16; i++) { WriteSomethingLikeNodeRecord(channel, idGenerator.NextId(), i); } } using (JumpingFileChannel channel = ( JumpingFileChannel )offsetFileSystem.Open(fileName, OpenMode.READ_WRITE)) { idGenerator = (new JumpingIdGeneratorFactory(10)).Get(IdType.NODE); for (int i = 0; i < 16; i++) { assertEquals(i, ReadSomethingLikeNodeRecord(channel, idGenerator.NextId())); } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expected = org.neo4j.graphdb.TransientTransactionFailureException.class) public void shouldTranslateComExceptionsIntoTransientTransactionFailures() public virtual void ShouldTranslateComExceptionsIntoTransientTransactionFailures() { when(_master.allocateIds(Null, any(typeof(IdType)))).thenThrow(new ComException()); IdGenerator generator = SwitchToSlave(); generator.NextId(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void slaveIdGeneratorShouldAskForMoreWhenRangeIsOver() public virtual void SlaveIdGeneratorShouldAskForMoreWhenRangeIsOver() { // GIVEN IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, 123), 42 + 123, 0); IdAllocation secondResult = new IdAllocation(new IdRange(new long[] {}, 1042, 223), 1042 + 223, 0); Response <IdAllocation> response = response(firstResult, secondResult); when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response); // WHEN IdGenerator gen = SwitchToSlave(); // THEN long startAt = firstResult.IdRange.RangeStart; long forThatMany = firstResult.IdRange.RangeLength; for (long i = startAt; i < startAt + forThatMany; i++) { assertEquals(i, gen.NextId()); } verify(_master, times(1)).allocateIds(Null, eq(IdType.NODE)); startAt = secondResult.IdRange.RangeStart; forThatMany = secondResult.IdRange.RangeLength; for (long i = startAt; i < startAt + forThatMany; i++) { assertEquals(i, gen.NextId()); } verify(_master, times(2)).allocateIds(Null, eq(IdType.NODE)); }
private IdGenerator SwitchToSlave() { _fac.switchToSlave(); IdGenerator gen = _fac.open(new File("someFile"), 10, IdType.NODE, () => 1L, Standard.LATEST_RECORD_FORMATS.node().MaxId); _masterDelegate.Delegate = _master; return(gen); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void openFilteredGenerator() public virtual void OpenFilteredGenerator() { FreeIdFilteredIdGeneratorFactory filteredGenerator = CreateFilteredFactory(); IdType idType = IdType.NODE; long highId = 1L; long maxId = 10L; System.Func <long> highIdSupplier = () => highId; IdGenerator idGenerator = filteredGenerator.Open(_file, idType, highIdSupplier, maxId); verify(_idGeneratorFactory).open(eq(_file), eq(idType), any(typeof(System.Func <long>)), eq(maxId)); assertThat(idGenerator, instanceOf(typeof(FreeIdFilteredIdGenerator))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDeleteIdGeneratorsAsPartOfOpenAfterSwitchingToSlave() public virtual void ShouldDeleteIdGeneratorsAsPartOfOpenAfterSwitchingToSlave() { // GIVEN we're in master mode. We do that to allow HaIdGeneratorFactory to open id generators at all _fac.switchToSlave(); File idFile = new File("my.id"); // ... opening an id generator as master _fac.create(idFile, 10, true); // WHEN IdGenerator idGenerator = _fac.open(idFile, 10, IdType.NODE, () => 10L, Standard.LATEST_RECORD_FORMATS.node().MaxId); // THEN assertFalse("Id file should've been deleted by now", _fs.fileExists(idFile)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReportCorrectHighId() public virtual void ShouldReportCorrectHighId() { // given using (IdGenerator idGenerator = CreateIdGenerator(2)) { assertEquals(0, idGenerator.HighId); assertEquals(-1, idGenerator.HighestPossibleIdInUse); // when idGenerator.NextId(); // then assertEquals(1, idGenerator.HighId); assertEquals(0, idGenerator.HighestPossibleIdInUse); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void slaveIdGeneratorShouldReturnFromAssignedRange() public virtual void SlaveIdGeneratorShouldReturnFromAssignedRange() { // GIVEN IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, 123), 123, 0); Response <IdAllocation> response = response(firstResult); when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response); // WHEN IdGenerator gen = SwitchToSlave(); // THEN for (long i = firstResult.IdRange.RangeStart; i < firstResult.IdRange.RangeLength; i++) { assertEquals(i, gen.NextId()); } verify(_master, times(1)).allocateIds(Null, eq(IdType.NODE)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMoveFromDefraggedToRange() public virtual void ShouldMoveFromDefraggedToRange() { // GIVEN long[] defragIds = new long[] { 42, 27172828, 314159 }; IdAllocation firstResult = new IdAllocation(new IdRange(defragIds, 0, 10), 100, defragIds.Length); Response <IdAllocation> response = response(firstResult); when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response); // WHEN IdGenerator gen = SwitchToSlave(); // THEN foreach (long defragId in defragIds) { assertEquals(defragId, gen.NextId()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void slaveShouldNeverAllowReducingHighId() public virtual void SlaveShouldNeverAllowReducingHighId() { // GIVEN const int highIdFromAllocation = 123; IdAllocation firstResult = new IdAllocation(new IdRange(new long[] {}, 42, highIdFromAllocation), highIdFromAllocation, 0); Response <IdAllocation> response = response(firstResult); when(_master.allocateIds(Null, any(typeof(IdType)))).thenReturn(response); // WHEN IdGenerator gen = SwitchToSlave(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int highIdFromUpdatedRecord = highIdFromAllocation + 1; int highIdFromUpdatedRecord = highIdFromAllocation + 1; gen.HighId = highIdFromUpdatedRecord; // Assume this is from a received transaction gen.NextId(); // that will ask the master for an IdRange // THEN assertEquals(highIdFromUpdatedRecord, gen.HighId); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void createContextWithProvidedReusabilityCheck() internal virtual void CreateContextWithProvidedReusabilityCheck() { IdReuseEligibility reuseEligibility = mock(typeof(IdReuseEligibility)); IdContextFactory contextFactory = IdContextFactoryBuilder.Of(_fs, _jobScheduler).withIdReuseEligibility(reuseEligibility).build(); DatabaseIdContext idContext = contextFactory.CreateIdContext("database"); IdGeneratorFactory bufferedGeneratorFactory = idContext.IdGeneratorFactory; assertThat(bufferedGeneratorFactory, instanceOf(typeof(BufferingIdGeneratorFactory))); BufferingIdGeneratorFactory bufferedFactory = ( BufferingIdGeneratorFactory )bufferedGeneratorFactory; KernelTransactionsSnapshot snapshot = mock(typeof(KernelTransactionsSnapshot)); when(snapshot.AllClosed()).thenReturn(true); bufferedFactory.Initialize(() => snapshot); using (IdGenerator idGenerator = bufferedFactory.Open(_testDirectory.file("a"), IdType.PROPERTY, () => 100, 100)) { idGenerator.FreeId(15); bufferedFactory.Maintenance(); verify(reuseEligibility).isEligible(snapshot); } }
public override IdAllocation AllocateIds(IdType idType) { IdGenerator generator = _idGeneratorFactory.get(idType); return(new IdAllocation(generator.NextIdBatch(ID_GRAB_SIZE), generator.HighId, generator.DefragCount)); }
private FreeIdFilteredIdGenerator CreateFilteredIdGenerator(IdGenerator idGenerator, System.Func <bool> booleanSupplier) { return(new FreeIdFilteredIdGenerator(idGenerator, booleanSupplier)); }
internal FreeIdFilteredIdGenerator(IdGenerator @delegate, System.Func <bool> freeIdCondition) : base(@delegate) { this._freeIdCondition = freeIdCondition; }