Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public final org.neo4j.helpers.collection.Pair<java.io.File, KeyValueStoreFile> open() throws java.io.IOException
        public Pair <File, KeyValueStoreFile> Open()
        {
            KeyValueStoreFile result = null;
            File path = null;

            foreach (File candidatePath in CandidateFiles())
            {
                KeyValueStoreFile file;
                if (Fs.fileExists(candidatePath))
                {
                    try
                    {
                        file = _format.openStore(Fs, Pages, candidatePath);
                    }
                    catch (Exception e)
                    {
                        _monitor.failedToOpenStoreFile(candidatePath, e);
                        continue;
                    }
                    if (result == null || _format.compareHeaders(result.Headers(), file.Headers()) < 0)
                    {
                        if (result != null)
                        {
                            result.Dispose();
                        }
                        result = file;
                        path   = candidatePath;
                    }
                    else
                    {
                        file.Dispose();
                    }
                }
            }
            return(result == null ? null : Pair.of(path, result));
        }
Example #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());
            }
        }