コード例 #1
0
 public SimpleFileStorage(FileSystemAbstraction fileSystem, File directory, string name, ChannelMarshal <T> marshal, LogProvider logProvider)
 {
     this._fileSystem = fileSystem;
     this._log        = logProvider.getLog(this.GetType());
     this._file       = new File(DurableStateStorage.StateDir(directory, name), name);
     this._marshal    = marshal;
 }
コード例 #2
0
            internal LongState(FileSystemAbstraction fileSystemAbstraction, File stateDir, int numberOfEntriesBeforeRotation)
            {
                LifeSupport.start();

                StateMarshal <long> byteBufferMarshal = new SafeStateMarshalAnonymousInnerClass(this);

                this.StateStorage = LifeSupport.add(new DurableStateStorage <>(fileSystemAbstraction, stateDir, FILENAME, byteBufferMarshal, numberOfEntriesBeforeRotation, NullLogProvider.Instance));

                this.TheStateConflict = this.StateStorage.InitialState;
            }
コード例 #3
0
//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());
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMaintainStateGivenAnEmptyInitialStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMaintainStateGivenAnEmptyInitialStore()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            DurableStateStorage <AtomicInteger> storage = _lifeRule.add(new DurableStateStorage <AtomicInteger>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), 100, NullLogProvider.Instance));

            // when
            storage.PersistStoreData(new AtomicInteger(99));

            // then
            assertEquals(4, fsa.GetFileSize(StateFileA()));
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRotateToOtherStoreFileAfterSufficientEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRotateToOtherStoreFileAfterSufficientEntries()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            const int numberOfEntriesBeforeRotation     = 100;
            DurableStateStorage <AtomicInteger> storage = _lifeRule.add(new DurableStateStorage <AtomicInteger>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), numberOfEntriesBeforeRotation, NullLogProvider.Instance));

            // when
            for (int i = 0; i < numberOfEntriesBeforeRotation; i++)
            {
                storage.PersistStoreData(new AtomicInteger(i));
            }

            // Force the rotation
            storage.PersistStoreData(new AtomicInteger(9999));

            // then
            assertEquals(4, fsa.GetFileSize(StateFileB()));
            assertEquals(numberOfEntriesBeforeRotation * 4, fsa.GetFileSize(StateFileA()));
        }