コード例 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowIllegalStateExceptionAfterClosed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowIllegalStateExceptionAfterClosed()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = new java.io.File(directory.directory(), "file");
            File         file         = new File(Directory.directory(), "file");
            StoreChannel storeChannel = FileSystemRule.get().open(file, OpenMode.READ_WRITE);
            PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1);
            PhysicalFlushableChannel         channel = new PhysicalFlushableChannel(versionedStoreChannel);

            // closing the WritableLogChannel, then the underlying channel is what PhysicalLogFile does
            channel.Dispose();
            storeChannel.close();

            // WHEN just appending something to the buffer
            channel.Put(( sbyte )0);
            // and wanting to empty that into the channel
            try
            {
                channel.PrepareForFlush();
                fail("Should have thrown exception");
            }
            catch (System.InvalidOperationException)
            {
                // THEN we should get an IllegalStateException, not a ClosedChannelException
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowClosedChannelExceptionWhenChannelUnexpectedlyClosed()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = new java.io.File(directory.directory(), "file");
            File         file         = new File(Directory.directory(), "file");
            StoreChannel storeChannel = FileSystemRule.get().open(file, OpenMode.READ_WRITE);
            PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1);
            PhysicalFlushableChannel         channel = new PhysicalFlushableChannel(versionedStoreChannel);

            // just close the underlying channel
            storeChannel.close();

            // WHEN just appending something to the buffer
            channel.Put(( sbyte )0);
            // and wanting to empty that into the channel
            try
            {
                channel.PrepareForFlush();
                fail("Should have thrown exception");
            }
            catch (ClosedChannelException)
            {
                // THEN we should get a ClosedChannelException
            }
        }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void writeState(T state) throws java.io.IOException
        public override void WriteState(T state)
        {
            _fileSystem.mkdirs(_file.ParentFile);
            _fileSystem.deleteFile(_file);

            using (FlushableChannel channel = new PhysicalFlushableChannel(_fileSystem.create(_file)))
            {
                _marshal.marshal(state, channel);
            }
        }
コード例 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteThroughRotation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteThroughRotation()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File firstFile = new java.io.File(directory.directory(), "file1");
            File firstFile = new File(Directory.directory(), "file1");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File secondFile = new java.io.File(directory.directory(), "file2");
            File         secondFile   = new File(Directory.directory(), "file2");
            StoreChannel storeChannel = FileSystemRule.get().open(firstFile, OpenMode.READ_WRITE);
            PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1);
            PhysicalFlushableChannel         channel = new PhysicalFlushableChannel(versionedStoreChannel);

            // WHEN writing a transaction, of sorts
            sbyte  byteValue   = ( sbyte )4;
            short  shortValue  = ( short )10;
            int    intValue    = 3545;
            long   longValue   = 45849589L;
            float  floatValue  = 45849.332f;
            double doubleValue = 458493343D;

            sbyte[] byteArrayValue = new sbyte[] { 1, 4, 2, 5, 3, 6 };

            channel.Put(byteValue);
            channel.PutShort(shortValue);
            channel.PutInt(intValue);
            channel.PutLong(longValue);
            channel.PrepareForFlush().flush();
            channel.Dispose();

            // "Rotate" and continue
            storeChannel    = FileSystemRule.get().open(secondFile, OpenMode.READ_WRITE);
            channel.Channel = new PhysicalLogVersionedStoreChannel(storeChannel, 2, ( sbyte )-1);
            channel.PutFloat(floatValue);
            channel.PutDouble(doubleValue);
            channel.Put(byteArrayValue, byteArrayValue.Length);
            channel.Dispose();

            // The two chunks of values should end up in two different files
            ByteBuffer firstFileContents = ReadFile(firstFile);

            assertEquals(byteValue, firstFileContents.get());
            assertEquals(shortValue, firstFileContents.Short);
            assertEquals(intValue, firstFileContents.Int);
            assertEquals(longValue, firstFileContents.Long);
            ByteBuffer secondFileContents = ReadFile(secondFile);

            assertEquals(floatValue, secondFileContents.Float, 0.0f);
            assertEquals(doubleValue, secondFileContents.Double, 0.0d);

            sbyte[] readByteArray = new sbyte[byteArrayValue.Length];
            secondFileContents.get(readByteArray);
            assertArrayEquals(byteArrayValue, readByteArray);
        }
コード例 #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToWriteValuesGreaterThanHalfTheBufferSize() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToWriteValuesGreaterThanHalfTheBufferSize()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File firstFile = new java.io.File(directory.directory(), "file1");
            File         firstFile    = new File(Directory.directory(), "file1");
            StoreChannel storeChannel = FileSystemRule.get().open(firstFile, OpenMode.READ_WRITE);
            PhysicalLogVersionedStoreChannel versionedStoreChannel = new PhysicalLogVersionedStoreChannel(storeChannel, 1, ( sbyte )-1);
            PhysicalFlushableChannel         channel = new PhysicalFlushableChannel(versionedStoreChannel);

            int length = 262_145;

            sbyte[] bytes = GenerateBytes(length);

            channel.Put(bytes, length);
            channel.Dispose();

            sbyte[] writtenBytes = new sbyte[length];
            using (Stream @in = new FileStream(firstFile, FileMode.Open, FileAccess.Read))
            {
                @in.Read(writtenBytes, 0, writtenBytes.Length);
            }

            assertArrayEquals(bytes, writtenBytes);
        }