Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: ActiveState<Key> rotate(boolean force, RotationStrategy strategy, RotationTimerFactory timerFactory, System.Action<Headers.Builder> headersUpdater) throws java.io.IOException
            internal override ActiveState <Key> Rotate(bool force, RotationStrategy strategy, RotationTimerFactory timerFactory, System.Action <Headers.Builder> headersUpdater)
            {
                if (!force)
                {
                    RotationTimerFactory.RotationTimer rotationTimer = timerFactory.CreateTimer();
                    for (long expected = Threshold - PreState.store.version(), sleep = 10; PreState.applied() < expected; sleep = Math.Min(sleep * 2, 100))
                    {
                        if (rotationTimer.TimedOut)
                        {
                            throw new RotationTimeoutException(Threshold, PreState.store.version(), rotationTimer.ElapsedTimeMillis);
                        }
                        try
                        {
                            Thread.Sleep(sleep);
                        }
                        catch (InterruptedException e)
                        {
                            throw ( InterruptedIOException )(new InterruptedIOException("Rotation was interrupted.")).initCause(e);
                        }
                    }
                }
                Pair <File, KeyValueStoreFile> next = strategy.Next(File(), UpdateHeaders(headersUpdater), KeyFormat().filter(PreState.dataProvider()));

                return(PostState.create(ReadableState.Store(PreState.keyFormat(), next.Other()), next.First(), PreState.versionContextSupplier));
            }
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 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());
            }
        }