internal virtual Headers Headers(IDictionary <string, sbyte[]> headers) { Headers.Builder builder = Headers.HeadersBuilder(); foreach (KeyValuePair <string, sbyte[]> entry in headers.SetOfKeyValuePairs()) { builder.Put(HeaderFields[entry.Key], entry.Value); } return(builder.Headers()); }
protected internal override Headers InitialHeaders(long version) { Headers.Builder builder = Headers.HeadersBuilder(); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (HeaderField<?> field : headerFields) foreach (HeaderField <object> field in HeaderFields) { PutHeader(builder, field); } return(builder.Headers()); }
//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 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()); } }