Ejemplo n.º 1
0
//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);
        }
Ejemplo n.º 2
0
//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));
            }
        }
Ejemplo n.º 3
0
 public virtual void Close(long highId)
 {
     if (!_closed)
     {
         try
         {
             _freeIdKeeper.Dispose();
             WriteHeader(highId);
             MarkAsCleanlyClosed();
             CloseChannel();
         }
         catch (IOException e)
         {
             throw new UnderlyingStorageException("Unable to close id file " + _file, e);
         }
     }
 }
Ejemplo n.º 4
0
//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));
            }
        }
Ejemplo n.º 5
0
//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);
        }