//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void persistedIdsShouldStillBeCounted() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void PersistedIdsShouldStillBeCounted() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = new FreeIdKeeper(channel, batchSize, true); // when // we store enough ids to cause overflow to file for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // and then some more int extraIds = 3; for (int i = batchSize; i < batchSize + extraIds; i++) { keeper.FreeId(i); } // then // the count should be returned correctly assertEquals(batchSize + extraIds, keeper.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldOnlyOverflowWhenThresholdIsReached() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldOnlyOverflowWhenThresholdIsReached() { // Given StoreChannel channel = spy(Fs.get().open(new File("id.file"), OpenMode.READ_WRITE)); int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); reset(channel); // because we get the position in the constructor, we need to reset all calls on the spy // when // we free 9 ids for (int i = 0; i < batchSize - 1; i++) { keeper.FreeId(i); } // then verifyZeroInteractions(channel); // when we free one more keeper.FreeId(10); // then verify(channel).writeAll(any(typeof(ByteBuffer))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldFirstReturnNonPersistedIdsAndThenPersistedOnesWhenAggressiveMode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldFirstReturnNonPersistedIdsAndThenPersistedOnesWhenAggressiveMode() { // this is testing the stack property, but from the viewpoint of avoiding unnecessary disk reads // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); // when // we store enough ids to cause overflow to file for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // and then some more int extraIds = 3; for (int i = batchSize; i < batchSize + extraIds; i++) { keeper.FreeId(i); } // then // the first returned should be the newly freed ones for (int i = batchSize; i < batchSize + extraIds; i++) { assertEquals(i, keeper.Id); } // and then there should be the persisted ones for (int i = 0; i < batchSize; i++) { assertEquals(i, keeper.Id); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadBackManyPersistedIdBatchesWhenAggressiveModeIsSet() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReadBackManyPersistedIdBatchesWhenAggressiveModeIsSet() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); ISet <long> freeIds = new HashSet <long>(); // when // we store enough ids to cause overflow to file, in two batches for (long i = 0; i < batchSize * 2; i++) { keeper.FreeId(i); freeIds.Add(i); } // then // they should be returned assertEquals(freeIds.Count, keeper.Count); for (int i = batchSize * 2 - 1; i >= 0; i--) { assertTrue(freeIds.remove(keeper.Id)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStoreAndRestoreIds() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStoreAndRestoreIds() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); ISet <long> freeIds = new HashSet <long>(); // stack guarantees are not maintained between restarts // when // we store enough ids to cause overflow to file for (long i = 0; i < batchSize; i++) { keeper.FreeId(i); freeIds.Add(i); } // and then some more int extraIds = 3; for (long i = batchSize; i < batchSize + extraIds; i++) { keeper.FreeId(i); freeIds.Add(i); } // and then we close the keeper keeper.Dispose(); channel.close(); // and then we open a new one over the same file channel = Fs.get().open(new File("id.file"), OpenMode.READ_WRITE); keeper = GetFreeIdKeeperAggressive(channel, batchSize); // then // the count should be returned correctly assertEquals(batchSize + extraIds, keeper.Count); assertEquals(freeIds.Count, keeper.Count); // and the ids, including the ones that did not cause a write, are still there (as a stack) for (int i = batchSize + extraIds - 1; i >= 0; i--) { long id = keeper.Id; assertTrue(freeIds.Contains(id)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allocateBatchWhenHaveLessIdsInMemoryButHaveOnDiskMore() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AllocateBatchWhenHaveLessIdsInMemoryButHaveOnDiskMore() { FreeIdKeeper freeIdKeeper = GetFreeIdKeeperAggressive(4); for (long id = 1L; id < 11L; id++) { freeIdKeeper.FreeId(id); } long[] ids = freeIdKeeper.GetIds(7); assertArrayEquals(new long[] { 9L, 10L, 5L, 6L, 7L, 8L, 1L }, ids); assertEquals(3, freeIdKeeper.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotReturnNewlyReleasedIdsIfAggressiveIsFalse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotReturnNewlyReleasedIdsIfAggressiveIsFalse() { // given FreeIdKeeper keeper = FreeIdKeeper; // when keeper.FreeId(1); long nextFree = keeper.Id; // then assertEquals(NO_RESULT, nextFree); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allocateBatchWhenHaveLessIdsInMemoryAndOnDisk() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AllocateBatchWhenHaveLessIdsInMemoryAndOnDisk() { FreeIdKeeper freeIdKeeper = GetFreeIdKeeperAggressive(4); for (long id = 1L; id < 10L; id++) { freeIdKeeper.FreeId(id); } long[] ids = freeIdKeeper.GetIds(15); assertArrayEquals(new long[] { 9L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L }, ids); assertEquals(0, freeIdKeeper.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void allocateBatchWhenHaveLessIdsInMemory() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void AllocateBatchWhenHaveLessIdsInMemory() { FreeIdKeeper freeIdKeeper = FreeIdKeeperAggressive; for (long id = 1L; id < 4L; id++) { freeIdKeeper.FreeId(id); } long[] ids = freeIdKeeper.GetIds(5); assertArrayEquals(new long[] { 1L, 2L, 3L }, ids); assertEquals(0, freeIdKeeper.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnMinusOneWhenRunningOutOfIds() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReturnMinusOneWhenRunningOutOfIds() { // Given FreeIdKeeper keeper = FreeIdKeeperAggressive; // when keeper.FreeId(13); // then assertEquals(13, keeper.Id); assertEquals(NO_RESULT, keeper.Id); assertEquals(NO_RESULT, keeper.Id); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCompactFileOnCloseInRegularMode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCompactFileOnCloseInRegularMode() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeper(channel, batchSize); // free 4 batches for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(i); } keeper.Dispose(); assertEquals(channel.size(), 4 * batchSize * Long.BYTES); channel.close(); // after opening again the IDs should be free to reuse channel = StoreChannel; keeper = GetFreeIdKeeper(channel, batchSize); // free 4 more batches on top of the already existing 4 for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(i); } // fetch 2 batches for (int i = 0; i < batchSize * 2; i++) { keeper.Id; } keeper.Dispose(); // when assertEquals(channel.size(), 6 * batchSize * Long.BYTES); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnNoResultIfIdsAreRestoredAndExhaustedAndThereAreFreeIdsFromThisRunWithAggressiveFalse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReturnNoResultIfIdsAreRestoredAndExhaustedAndThereAreFreeIdsFromThisRunWithAggressiveFalse() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeper(channel, batchSize); ISet <long> freeIds = new HashSet <long>(); for (long i = 0; i < batchSize; i++) { keeper.FreeId(i); freeIds.Add(i); } keeper.Dispose(); channel.close(); // and then we open a new one over the same file channel = Fs.get().open(new File("id.file"), OpenMode.READ_WRITE); keeper = GetFreeIdKeeper(channel, batchSize); // when - then // we exhaust all ids restored for (int i = 0; i < batchSize; i++) { assertTrue(freeIds.remove(keeper.Id)); } // when // we release some ids that spill to disk for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // then // we should have no ids to return assertEquals(NO_RESULT, keeper.Id); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotReturnReusedIdsAfterRestart() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotReturnReusedIdsAfterRestart() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); long idGen = 0; // free 4 batches for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(idGen++); } // reuse 2 batches IList <long> reusedIds = new List <long>(); for (int i = 0; i < batchSize * 2; i++) { long id = keeper.Id; reusedIds.Add(id); } // when keeper.Dispose(); channel.close(); channel = StoreChannel; keeper = GetFreeIdKeeper(channel, batchSize); IList <long> remainingIds = new List <long>(); long id; while ((id = keeper.Id) != IdContainer.NO_RESULT) { remainingIds.Add(id); } assertEquals(2 * batchSize, remainingIds.Count); // then foreach (long?remainingId in remainingIds) { assertFalse(reusedIds.Contains(remainingId)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void freeingAnIdShouldReturnThatIdAndUpdateTheCountWhenAggressiveModeIsSet() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void FreeingAnIdShouldReturnThatIdAndUpdateTheCountWhenAggressiveModeIsSet() { // Given FreeIdKeeper keeper = FreeIdKeeperAggressive; // when keeper.FreeId(13); // then assertEquals(1, keeper.Count); // when long result = keeper.Id; // then assertEquals(13, result); assertEquals(0, keeper.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotReturnIdsPersistedDuringThisRunIfAggressiveIsFalse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotReturnIdsPersistedDuringThisRunIfAggressiveIsFalse() { // given StoreChannel channel = spy(Fs.get().open(new File("id.file"), OpenMode.READ_WRITE)); int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeper(channel, batchSize); // when // enough ids are persisted to overflow for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // then // stuff must have been written to disk verify(channel, times(1)).write(any(typeof(ByteBuffer))); // and no ids can be returned assertEquals(NO_RESULT, keeper.Id); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadBackPersistedIdsWhenAggressiveModeIsSet() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReadBackPersistedIdsWhenAggressiveModeIsSet() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); // when // we store enough ids to cause overflow to file for (int i = 0; i < batchSize; i++) { keeper.FreeId(i); } // then // they should be returned in order for (int i = 0; i < batchSize; i++) { assertEquals(i, keeper.Id); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTruncateFileInAggressiveMode() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTruncateFileInAggressiveMode() { // given StoreChannel channel = StoreChannel; int batchSize = 10; FreeIdKeeper keeper = GetFreeIdKeeperAggressive(channel, batchSize); // free 4 batches for (long i = 0; i < batchSize * 4; i++) { keeper.FreeId(i); } assertEquals(channel.size(), 4 * batchSize * Long.BYTES); // when for (int i = 0; i < batchSize * 2; i++) { keeper.Id; } // then assertEquals(channel.size(), 2 * batchSize * Long.BYTES); }