//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static void assertFind(KeyValueStoreFile file, int min, int max, boolean exact, Bytes... expected) throws java.io.IOException
        private static void AssertFind(KeyValueStoreFile file, int min, int max, bool exact, params Bytes[] expected)
        {
            Pair <bool, IList <Bytes> > result = Find(file, min, max);

            assertEquals("exact match", exact, result.First());
            assertEquals(string.Format("find(min={0:D}, max={1:D})", min, max), Arrays.asList(expected), result.Other());
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static void assertEntries(final int expected, KeyValueStoreFile file) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        internal static void AssertEntries(int expected, KeyValueStoreFile file)
        {
//JAVA TO C# CONVERTER TODO TASK: Local classes are not converted by Java to C# Converter:
//			  class Visitor implements KeyValueVisitor
            //		  {
            //				int visited;
            //
            //				@@Override public boolean visit(ReadableBuffer key, ReadableBuffer value)
            //				{
            //					 if (++visited > expected)
            //					 {
            //						  fail("should not have more than " + expected + " data entries");
            //					 }
            //					 return true;
            //				}
            //
            //				void done()
            //				{
            //					 assertEquals("number of entries", expected, visited);
            //				}
            //		  }
            Visitor visitor = new Visitor();

            file.Scan(visitor);
            visitor.done();
        }
Exemple #3
0
 public DataProviderAnonymousInnerClass(KeyValueStoreFile outerInstance, PageCursor cursor)
 {
     this.outerInstance = outerInstance;
     this._cursor       = cursor;
     offset             = outerInstance.headerEntries * (outerInstance.keySize + outerInstance.valueSize);
     done = !cursor.Next();
 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFindEntriesInFile() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFindEntriesInFile()
        {
            // given
            Format format = new Format(this, "one", "two");
            IDictionary <string, sbyte[]> headers = new Dictionary <string, sbyte[]>();

            headers["one"] = new sbyte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            headers["two"] = new sbyte[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };
            IDictionary <string, string> config = new Dictionary <string, string>();

            config[GraphDatabaseSettings.pagecache_memory.name()] = "8M";
            Data data = data(entry(Bytes(17), Bytes('v', 'a', 'l', 1)), entry(Bytes(22), Bytes('v', 'a', 'l', 2)), entry(Bytes(22), Bytes('v', 'a', 'l', 3)), entry(Bytes(25), Bytes('v', 'a', 'l', 4)), entry(Bytes(27), Bytes('v', 'a', 'l', 5)), entry(Bytes(27), Bytes('v', 'a', 'l', 6)), entry(Bytes(31), Bytes('v', 'a', 'l', 7)), entry(Bytes(63), Bytes('v', 'a', 'l', 8)), entry(Bytes(127), Bytes('v', 'a', 'l', 9)), entry(Bytes(255), Bytes('v', 'a', 'l', 10)), entry(Bytes(511), Bytes('v', 'a', 'l', 11)), entry(Bytes(1023), Bytes('v', 'a', 'l', 12)), entry(Bytes(1050), Bytes('v', 'a', 'l', 13)), entry(Bytes(2000), Bytes('v', 'a', 'l', 14)));

            // when
            using (KeyValueStoreFile file = format.Create(config, headers, data))
            {
                // then
                AssertFind(file, 17, 17, true, new Bytes('v', 'a', 'l', 1));
                AssertFind(file, 22, 22, true, new Bytes('v', 'a', 'l', 2), new Bytes('v', 'a', 'l', 3));
                AssertFind(file, 25, 25, true, new Bytes('v', 'a', 'l', 4));
                AssertFind(file, 27, 27, true, new Bytes('v', 'a', 'l', 5), new Bytes('v', 'a', 'l', 6));
                AssertFind(file, 26, 30, false, new Bytes('v', 'a', 'l', 5), new Bytes('v', 'a', 'l', 6));
                AssertFind(file, 31, 31, true, new Bytes('v', 'a', 'l', 7));
                AssertFind(file, 32, 1024, false, new Bytes('v', 'a', 'l', 8), new Bytes('v', 'a', 'l', 9), new Bytes('v', 'a', 'l', 10), new Bytes('v', 'a', 'l', 11), new Bytes('v', 'a', 'l', 12));
                AssertFind(file, 1050, 1050, true, new Bytes('v', 'a', 'l', 13));
                AssertFind(file, 2000, 2000, true, new Bytes('v', 'a', 'l', 14));
                AssertFind(file, 1500, 8000, false, new Bytes('v', 'a', 'l', 14));
                AssertFind(file, 1050, 8000, true, new Bytes('v', 'a', 'l', 13), new Bytes('v', 'a', 'l', 14));
                AssertFind(file, 2001, int.MaxValue, false);
            }
        }
Exemple #5
0
            internal override KeyValueStoreFile Open(Metadata metadata, int keySize, int valueSize)
            {
                KeyValueStoreFile result = new KeyValueStoreFile(File, keySize, valueSize, metadata);

                Opened = true;
                return(result);
            }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateAndOpenStoreWithNoDataAndEmptyHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateAndOpenStoreWithNoDataAndEmptyHeader()
        {
            // given
            Format format = new Format(this);

            // when
            using (KeyValueStoreFile file = format.Create(NoHeaders(), NoData()))
            {
                // then
                assertTrue(file.Headers().fields().Count == 0);
                AssertEntries(0, file);
            }
        }
Exemple #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: protected final void visitFile(java.io.File path, Visitor visitor) throws java.io.IOException
        protected internal void VisitFile(File path, Visitor visitor)
        {
            using (KeyValueStoreFile file = RotationStrategy.openStoreFile(path))
            {
                if (visitor is MetadataVisitor)
                {
                    (( MetadataVisitor )visitor).VisitMetadata(path, file.Headers(), file.EntryCount());
                }
                using (DataProvider provider = file.DataProvider())
                {
                    Transfer(provider, visitor);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailAfterEnoughAttempts() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailAfterEnoughAttempts()
        {
            // given
            WritableBuffer buffer = mock(typeof(WritableBuffer));
            PageCursor     cursor = mock(typeof(PageCursor));

            when(cursor.ShouldRetry()).thenReturn(true);
            when(cursor.CurrentFile).thenReturn(new File("foo/bar.a"));

            // then
            Exception.expect(typeof(UnderlyingStorageException));

            // when
            KeyValueStoreFile.ReadKeyValuePair(cursor, 42, buffer, buffer);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateAndOpenStoreWithDataAndEmptyHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateAndOpenStoreWithDataAndEmptyHeader()
        {
            // given
            Format format = new Format(this);
            Data   data   = data(entry(new sbyte[] { ( sbyte )'o', ( sbyte )'n', ( sbyte )'e' }, new sbyte[] { ( sbyte )'a', ( sbyte )'l', ( sbyte )'p', ( sbyte )'h', ( sbyte )'a' }), entry(new sbyte[] { ( sbyte )'t', ( sbyte )'w', ( sbyte )'o' }, new sbyte[] { ( sbyte )'b', ( sbyte )'e', ( sbyte )'t', ( sbyte )'a' }), entry(new sbyte[] { ( sbyte )'z', ( sbyte )'e', ( sbyte )'d' }, new sbyte[] { ( sbyte )'o', ( sbyte )'m', ( sbyte )'e', ( sbyte )'g', ( sbyte )'a' }));

            // when
            using (KeyValueStoreFile file = format.Create(NoHeaders(), data))
            {
                // then
                assertTrue(file.Headers().fields().Count == 0);
                file.Scan(ExpectData(data));
                assertEquals("number of entries", 3, data.Index);
                AssertEntries(3, file);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateAndOpenStoreWithNoDataWithHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateAndOpenStoreWithNoDataWithHeader()
        {
            // given
            Format format = new Format(this, "abc", "xyz");
            IDictionary <string, sbyte[]> headers = new Dictionary <string, sbyte[]>();

            headers["abc"] = new sbyte[] { ( sbyte )'h', ( sbyte )'e', ( sbyte )'l', ( sbyte )'l', ( sbyte )'o', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            headers["xyz"] = new sbyte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ( sbyte )'w', ( sbyte )'o', ( sbyte )'r', ( sbyte )'l', ( sbyte )'d' };

            // when
            using (KeyValueStoreFile file = format.Create(headers, NoData()))
            {
                // then
                AssertDeepEquals(headers, file.Headers());
                AssertEntries(0, file);
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static org.neo4j.helpers.collection.Pair<bool,java.util.List<Bytes>> find(KeyValueStoreFile file, final int min, final int max) throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
        private static Pair <bool, IList <Bytes> > Find(KeyValueStoreFile file, int min, int max)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.List<Bytes> values = new java.util.ArrayList<>();
            IList <Bytes> values = new List <Bytes>();
            bool          result = file.Scan(key => key.putInt(key.size() - 4, min), (key, value) =>
            {
                if (key.getInt(key.size() - 4) <= max)
                {
                    values.Add(new Bytes(value.get(0, new sbyte[value.size()])));
                    return(true);
                }
                return(false);
            });

            return(Pair.of(result, values));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateAndOpenEmptyStoreWithHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateAndOpenEmptyStoreWithHeader()
        {
            // given
            Format format = new Format(this, "foo", "bar");
            IDictionary <string, sbyte[]> headers = new Dictionary <string, sbyte[]>();

            headers["foo"] = new sbyte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ( sbyte )'f', ( sbyte )'o', ( sbyte )'o' };
            headers["bar"] = new sbyte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ( sbyte )'b', ( sbyte )'a', ( sbyte )'r' };

            // when
            format.CreateEmpty(headers);

            // then
            using (KeyValueStoreFile file = format.Open())
            {
                AssertDeepEquals(headers, file.Headers());
                AssertEntries(0, file);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTruncateTheFile() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTruncateTheFile()
        {
            IDictionary <string, string> config = new Dictionary <string, string>();

            config[GraphDatabaseSettings.pagecache_memory.name()] = "8M";

            {
                // given a well written file
                Format format = new Format(this, "one", "two");
                IDictionary <string, sbyte[]> headers = new Dictionary <string, sbyte[]>();
                headers["one"] = new sbyte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
                headers["two"] = new sbyte[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 };

                Data data = data(entry(Bytes(12), Bytes('v', 'a', 'l', 1)), entry(Bytes(13), Bytes('v', 'a', 'l', 2)), entry(Bytes(15), Bytes('v', 'a', 'l', 3)), entry(Bytes(16), Bytes('v', 'a', 'l', 4)), entry(Bytes(17), Bytes('v', 'a', 'l', 5)), entry(Bytes(18), Bytes('v', 'a', 'l', 6)));

                using (KeyValueStoreFile ignored = format.Create(config, headers, data))
                {
                }
            }

            {
                // when failing on creating the next version of that file
                Format format = new Format(this, "three", "four");
                IDictionary <string, sbyte[]> headers = new Dictionary <string, sbyte[]>();
                headers["three"] = new sbyte[] { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
                headers["four"]  = new sbyte[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };

                DataProvider data = new DataProviderAnonymousInnerClass(this);

                try
                {
                    using (KeyValueStoreFile ignored = format.Create(config, headers, data))
                    {
                    }
                }
                catch (IOException io)
                {
                    // then only headers are present in the file and not the old content
                    assertEquals("boom!", io.Message);
                    AssertFormatSpecifierAndHeadersOnly(headers, Fs.get(), StoreFile);
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindAnythingWhenSearchKeyIsAfterTheLastKey() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotFindAnythingWhenSearchKeyIsAfterTheLastKey()
        {
            // given
            Format format = new Format(this);
            IDictionary <string, sbyte[]> metadata = new Dictionary <string, sbyte[]>();
            IDictionary <string, string>  config   = new Dictionary <string, string>();

            config[GraphDatabaseSettings.pagecache_memory.name()] = "8M";
            Data data = data(entry(Bytes(12), Bytes('v', 'a', 'l', 1)), entry(Bytes(13), Bytes('v', 'a', 'l', 2)), entry(Bytes(15), Bytes('v', 'a', 'l', 3)), entry(Bytes(16), Bytes('v', 'a', 'l', 4)), entry(Bytes(17), Bytes('v', 'a', 'l', 5)), entry(Bytes(18), Bytes('v', 'a', 'l', 6)));

            // when
            using (KeyValueStoreFile file = format.Create(config, metadata, data))
            {
                // then
                AssertFind(file, 14, 15, false, new Bytes('v', 'a', 'l', 3)); // after the first page
                AssertFind(file, 19, 25, false);                              // after the second page
                AssertFind(file, 18, 25, true, new Bytes('v', 'a', 'l', 6));  // last entry of the last page
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCreateAndOpenStoreWithDataAndHeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCreateAndOpenStoreWithDataAndHeader()
        {
            // given
            Format format = new Format(this, "abc", "xyz");
            IDictionary <string, sbyte[]> headers = new Dictionary <string, sbyte[]>();

            headers["abc"] = new sbyte[] { ( sbyte )'h', ( sbyte )'e', ( sbyte )'l', ( sbyte )'l', ( sbyte )'o', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            headers["xyz"] = new sbyte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ( sbyte )'w', ( sbyte )'o', ( sbyte )'r', ( sbyte )'l', ( sbyte )'d' };
            Data data = data(entry(new sbyte[] { ( sbyte )'o', ( sbyte )'n', ( sbyte )'e' }, new sbyte[] { ( sbyte )'a', ( sbyte )'l', ( sbyte )'p', ( sbyte )'h', ( sbyte )'a' }), entry(new sbyte[] { ( sbyte )'t', ( sbyte )'w', ( sbyte )'o' }, new sbyte[] { ( sbyte )'b', ( sbyte )'e', ( sbyte )'t', ( sbyte )'a' }), entry(new sbyte[] { ( sbyte )'z', ( sbyte )'e', ( sbyte )'d' }, new sbyte[] { ( sbyte )'o', ( sbyte )'m', ( sbyte )'e', ( sbyte )'g', ( sbyte )'a' }));

            // when
            using (KeyValueStoreFile file = format.Create(headers, data))
            {
                // then
                AssertDeepEquals(headers, file.Headers());
                file.Scan(ExpectData(data));
                assertEquals("number of entries", 3, data.Index);
                AssertEntries(3, file);
            }
        }
Exemple #16
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));
        }
Exemple #17
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());
            }
        }