//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void removeLastCheckpointRecordFromLastLogFile() throws java.io.IOException private void RemoveLastCheckpointRecordFromLastLogFile() { LogPosition checkpointPosition = null; LogFile transactionLogFile = _logFiles.LogFile; VersionAwareLogEntryReader <ReadableLogChannel> entryReader = new VersionAwareLogEntryReader <ReadableLogChannel>(); LogPosition startPosition = LogPosition.start(_logFiles.HighestLogVersion); using (ReadableLogChannel reader = transactionLogFile.GetReader(startPosition)) { LogEntry logEntry; do { logEntry = entryReader.ReadLogEntry(reader); if (logEntry is CheckPoint) { checkpointPosition = (( CheckPoint )logEntry).LogPosition; } } while (logEntry != null); } if (checkpointPosition != null) { using (StoreChannel storeChannel = _fileSystemRule.open(_logFiles.HighestLogFile, OpenMode.READ_WRITE)) { storeChannel.Truncate(checkpointPosition.ByteOffset); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPickTheUncorruptedStoreWhenTruncatingAfterTheHeader() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPickTheUncorruptedStoreWhenTruncatingAfterTheHeader() { /* * The problem was that if we were successful in writing the header but failing immediately after, we would * read 0 as counter for entry data and pick the corrupted store thinking that it was simply empty. */ Store store = CreateTestStore(); Pair <File, KeyValueStoreFile> file = store.RotationStrategy.create(EMPTY_DATA_PROVIDER, 1); Pair <File, KeyValueStoreFile> next = store.RotationStrategy.next(file.First(), Headers.HeadersBuilder().put(TX_ID, (long)42).headers(), Data((Entry)(key, value) => { key.putByte(0, ( sbyte )'f'); key.putByte(1, ( sbyte )'o'); key.putByte(2, ( sbyte )'o'); value.putInt(0, 42); })); file.Other().Dispose(); File correct = next.First(); Pair <File, KeyValueStoreFile> nextNext = store.RotationStrategy.next(correct, Headers.HeadersBuilder().put(TX_ID, (long)43).headers(), Data((key, value) => { key.putByte(0, ( sbyte )'f'); key.putByte(1, ( sbyte )'o'); key.putByte(2, ( sbyte )'o'); value.putInt(0, 42); }, (key, value) => { key.putByte(0, ( sbyte )'b'); key.putByte(1, ( sbyte )'a'); key.putByte(2, ( sbyte )'r'); value.putInt(0, 4242); })); next.Other().Dispose(); File corrupted = nextNext.First(); nextNext.Other().Dispose(); using (StoreChannel channel = _resourceManager.fileSystem().open(corrupted, OpenMode.READ_WRITE)) { channel.Truncate(16 * 4); } // then using (Lifespan life = new Lifespan()) { life.Add(store); assertNotNull(store.Get("foo")); assertEquals(42L, store.Headers().get(TX_ID).longValue()); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public StoreChannel truncate(long size) throws java.io.IOException public override StoreChannel Truncate(long size) { return(@delegate.Truncate(Offset(size))); }