Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testClose()
        public virtual void TestClose()
        {
            DynamicArrayStore           store   = CreateDynamicArrayStore();
            ICollection <DynamicRecord> records = new List <DynamicRecord>();

            store.AllocateRecordsFromBytes(records, new sbyte[10]);
            long blockId = Iterables.first(records).Id;

            foreach (DynamicRecord record in records)
            {
                store.UpdateRecord(record);
            }
            _neoStores.close();
            _neoStores = null;
            try
            {
                store.GetArrayFor(store.GetRecords(blockId, NORMAL));
                fail("Closed store should throw exception");
            }
            catch (Exception)
            {               // good
            }
            try
            {
                store.GetRecords(0, NORMAL);
                fail("Closed store should throw exception");
            }
            catch (Exception)
            {               // good
            }
        }
Esempio n. 2
0
 public PropertyStore(File file, File idFile, Config configuration, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, DynamicStringStore stringPropertyStore, PropertyKeyTokenStore propertyKeyTokenStore, DynamicArrayStore arrayPropertyStore, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, configuration, IdType.PROPERTY, idGeneratorFactory, pageCache, logProvider, TYPE_DESCRIPTOR, recordFormats.Property(), NO_STORE_HEADER_FORMAT, recordFormats.StoreVersion(), openOptions)
 {
     this._stringStore            = stringPropertyStore;
     this._propertyKeyTokenStore  = propertyKeyTokenStore;
     this._arrayStore             = arrayPropertyStore;
     _allowStorePointsAndTemporal = recordFormats.HasCapability(Capability.POINT_PROPERTIES) && recordFormats.HasCapability(Capability.TEMPORAL_PROPERTIES);
 }
Esempio n. 3
0
        public static ICollection <DynamicRecord> AllocateRecordsForDynamicLabels(long nodeId, long[] labels, DynamicRecordAllocator allocator)
        {
            long[] storedLongs = LabelIdArray.PrependNodeId(nodeId, labels);
            ICollection <DynamicRecord> records = new List <DynamicRecord>();

            // since we can't store points in long array we passing false as possibility to store points
            DynamicArrayStore.AllocateRecords(records, storedLongs, allocator, false);
            return(records);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void before()
        public virtual void Before()
        {
            FileSystemAbstraction     fs = FileSystemRule.get();
            DefaultIdGeneratorFactory idGeneratorFactory = new DefaultIdGeneratorFactory(fs);
            PageCache    pageCache = PageCacheRule.getPageCache(fs);
            StoreFactory factory   = new StoreFactory(TestDirectory.databaseLayout(), Config.defaults(), idGeneratorFactory, pageCache, fs, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            _neoStores  = factory.OpenAllNeoStores(true);
            _arrayStore = _neoStores.PropertyStore.ArrayStore;
        }
Esempio n. 5
0
        private long Create(DynamicArrayStore store, object arrayToStore)
        {
            ICollection <DynamicRecord> records = new List <DynamicRecord>();

            store.AllocateRecords(records, arrayToStore);
            foreach (DynamicRecord record in records)
            {
                store.UpdateRecord(record);
            }
            return(Iterables.first(records).Id);
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRandomTest()
        public virtual void TestRandomTest()
        {
            Random                      random   = new Random(DateTimeHelper.CurrentUnixTimeMillis());
            DynamicArrayStore           store    = CreateDynamicArrayStore();
            List <long>                 idsTaken = new List <long>();
            IDictionary <long, sbyte[]> byteData = new Dictionary <long, sbyte[]>();
            float       deleteIndex  = 0.2f;
            float       closeIndex   = 0.1f;
            int         currentCount = 0;
            int         maxCount     = 128;
            ISet <long> set          = new HashSet <long>();

            while (currentCount < maxCount)
            {
                float rIndex = random.nextFloat();
                if (rIndex < deleteIndex && currentCount > 0)
                {
                    long blockId = idsTaken.Remove(random.Next(currentCount));
                    store.GetRecords(blockId, NORMAL);
                    sbyte[] bytes = ( sbyte[] )store.GetArrayFor(store.GetRecords(blockId, NORMAL));
                    ValidateData(bytes, byteData.Remove(blockId));
                    ICollection <DynamicRecord> records = store.GetRecords(blockId, NORMAL);
                    foreach (DynamicRecord record in records)
                    {
                        record.InUse = false;
                        store.UpdateRecord(record);
                        set.remove(record.Id);
                    }
                    currentCount--;
                }
                else
                {
                    sbyte[] bytes = CreateRandomBytes(random);
                    ICollection <DynamicRecord> records = new List <DynamicRecord>();
                    store.AllocateRecords(records, bytes);
                    foreach (DynamicRecord record in records)
                    {
                        Debug.Assert(!set.Contains(record.Id));
                        store.UpdateRecord(record);
                        set.Add(record.Id);
                    }
                    long blockId = Iterables.first(records).Id;
                    idsTaken.Add(blockId);
                    byteData[blockId] = bytes;
                    currentCount++;
                }
                if (rIndex > (1.0f - closeIndex) || rIndex < closeIndex)
                {
                    _neoStores.close();
                    store = CreateDynamicArrayStore();
                }
            }
        }
Esempio n. 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void verifyFixedSizeStoresCanRebuildIdGeneratorSlowly()
        public virtual void VerifyFixedSizeStoresCanRebuildIdGeneratorSlowly()
        {
            // Given we have a store ...
            Config config    = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");
            File   storeFile = _testDirectory.file("nodes");
            File   idFile    = _testDirectory.file("idNodes");

            DynamicArrayStore labelStore = mock(typeof(DynamicArrayStore));
            NodeStore         store      = new NodeStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), NullLogProvider.Instance, labelStore, RecordFormatSelector.defaultFormat());

            store.Initialise(true);
            store.MakeStoreOk();

            // ... that contain a number of records ...
            NodeRecord record = new NodeRecord(0);

            record.InUse = true;
            int highestId = 50;

            for (int i = 0; i < highestId; i++)
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                store.UpdateRecord(record);
            }
            store.HighestPossibleIdInUse = highestId;

            // ... and some have been deleted
            long?[] idsToFree = new long?[] { 2L, 3L, 5L, 7L };
            record.InUse = false;
            foreach (long toDelete in idsToFree)
            {
                record.Id = toDelete;
                store.UpdateRecord(record);
            }

            // Then when we rebuild the id generator
            store.RebuildIdGenerator();
            store.CloseIdGenerator();
            store.OpenIdGenerator();               // simulate a restart to allow id reuse

            // We should observe that the ids above got freed
            IList <long> nextIds = new List <long>();

            nextIds.Add(store.NextId());                 // 2
            nextIds.Add(store.NextId());                 // 3
            nextIds.Add(store.NextId());                 // 5
            nextIds.Add(store.NextId());                 // 7
            nextIds.Add(store.NextId());                 // 51
            assertThat(nextIds, contains(2L, 3L, 5L, 7L, 50L));
            store.Close();
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage()
        public virtual void RebuildingIdGeneratorMustNotMissOutOnFreeRecordsAtEndOfFilePage()
        {
            // Given we have a store ...
            Config config    = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");
            File   storeFile = _testDirectory.file("nodes");
            File   idFile    = _testDirectory.file("idNodes");

            DynamicArrayStore labelStore = mock(typeof(DynamicArrayStore));
            NodeStore         store      = new NodeStore(storeFile, idFile, config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), NullLogProvider.Instance, labelStore, RecordFormatSelector.defaultFormat());

            store.Initialise(true);
            store.MakeStoreOk();

            // ... that contain enough records to fill several file pages ...
            int        recordsPerPage = store.RecordsPerPage;
            NodeRecord record         = new NodeRecord(0);

            record.InUse = true;
            int highestId = recordsPerPage * 3;               // 3 pages worth of records

            for (int i = 0; i < highestId; i++)
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                store.UpdateRecord(record);
            }
            store.HighestPossibleIdInUse = highestId;

            // ... and some records at the end of a page have been deleted
            long?[] idsToFree = new long?[] { recordsPerPage - 2L, recordsPerPage - 1L };               // id's are zero based, hence -2 and -1
            record.InUse = false;
            foreach (long toDelete in idsToFree)
            {
                record.Id = toDelete;
                store.UpdateRecord(record);
            }

            // Then when we rebuild the id generator
            store.RebuildIdGenerator();
            store.CloseIdGenerator();
            store.OpenIdGenerator();               // simulate a restart to allow id reuse

            // We should observe that the ids above got freed
            IList <long> nextIds = new List <long>();

            nextIds.Add(store.NextId());                 // recordsPerPage - 2
            nextIds.Add(store.NextId());                 // recordsPerPage - 1
            nextIds.Add(store.NextId());                 // recordsPerPage * 3 (we didn't use this id in the create-look above)
            assertThat(nextIds, contains(recordsPerPage - 2L, recordsPerPage - 1L, recordsPerPage * 3L));
            store.Close();
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testStoreGetCharsFromString()
        public virtual void TestStoreGetCharsFromString()
        {
            const string      str   = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            DynamicArrayStore store = CreateDynamicArrayStore();

            char[] chars = new char[str.Length];
            str.CopyTo(0, chars, 0, str.Length - 0);
            ICollection <DynamicRecord> records = new List <DynamicRecord>();

            store.AllocateRecords(records, chars);
            foreach (DynamicRecord record in records)
            {
                store.UpdateRecord(record);
            }
            // assertEquals( STR, new String( store.getChars( blockId ) ) );
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAddDeleteSequenceEmptyStringArray()
        public virtual void TestAddDeleteSequenceEmptyStringArray()
        {
            DynamicArrayStore store = CreateDynamicArrayStore();
            long blockId            = Create(store, new string[0]);

            store.GetRecords(blockId, NORMAL);
            string[] readBack = ( string[] )store.GetArrayFor(store.GetRecords(blockId, NORMAL));
            assertEquals(0, readBack.Length);

            ICollection <DynamicRecord> records = store.GetRecords(blockId, NORMAL);

            foreach (DynamicRecord record in records)
            {
                record.InUse = false;
                store.UpdateRecord(record);
            }
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAddDeleteSequenceEmptyNumberArray()
        public virtual void TestAddDeleteSequenceEmptyNumberArray()
        {
            DynamicArrayStore store = CreateDynamicArrayStore();

            sbyte[] emptyToWrite = CreateBytes(0);
            long    blockId      = Create(store, emptyToWrite);

            store.GetRecords(blockId, NORMAL);
            sbyte[] bytes = ( sbyte[] )store.GetArrayFor(store.GetRecords(blockId, NORMAL));
            assertEquals(0, bytes.Length);

            ICollection <DynamicRecord> records = store.GetRecords(blockId, NORMAL);

            foreach (DynamicRecord record in records)
            {
                record.InUse = false;
                store.UpdateRecord(record);
            }
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void failStoreInitializationWhenHeaderRecordCantBeRead() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void FailStoreInitializationWhenHeaderRecordCantBeRead()
        {
            File       storeFile  = _dir.file("a");
            File       idFile     = _dir.file("idFile");
            PageCache  pageCache  = mock(typeof(PageCache));
            PagedFile  pagedFile  = mock(typeof(PagedFile));
            PageCursor pageCursor = mock(typeof(PageCursor));

            when(pageCache.Map(eq(storeFile), anyInt(), any(typeof(OpenOption)))).thenReturn(pagedFile);
            when(pagedFile.Io(0L, Org.Neo4j.Io.pagecache.PagedFile_Fields.PF_SHARED_READ_LOCK)).thenReturn(pageCursor);
            when(pageCursor.Next()).thenReturn(false);

            RecordFormats recordFormats = Standard.LATEST_RECORD_FORMATS;

            ExpectedException.expect(typeof(StoreNotFoundException));
            ExpectedException.expectMessage("Fail to read header record of store file: " + storeFile.AbsolutePath);

            using (DynamicArrayStore dynamicArrayStore = new DynamicArrayStore(storeFile, idFile, _config, IdType.NODE_LABELS, _idGeneratorFactory, pageCache, NullLogProvider.Instance, Settings.INTEGER.apply(GraphDatabaseSettings.label_block_size.DefaultValue), recordFormats))
            {
                dynamicArrayStore.Initialise(false);
            }
        }
Esempio n. 13
0
 private static void AllocateArrayRecords(ICollection <DynamicRecord> target, object array, DynamicRecordAllocator allocator, bool allowStorePoints)
 {
     DynamicArrayStore.AllocateRecords(target, array, allocator, allowStorePoints);
 }
Esempio n. 14
0
 public static Pair <long, long[]> GetDynamicLabelsArrayAndOwner(IEnumerable <DynamicRecord> records, AbstractDynamicStore dynamicLabelStore)
 {
     long[] storedLongs = ( long[] )DynamicArrayStore.GetRightArray(dynamicLabelStore.ReadFullByteArray(records, PropertyType.Array)).asObject();
     return(Pair.of(storedLongs[0], LabelIdArray.StripNodeId(storedLongs)));
 }
Esempio n. 15
0
 public static long[] GetDynamicLabelsArrayFromHeavyRecords(IEnumerable <DynamicRecord> records)
 {
     long[] storedLongs = ( long[] )DynamicArrayStore.GetRightArray(readFullByteArrayFromHeavyRecords(records, PropertyType.Array)).asObject();
     return(LabelIdArray.StripNodeId(storedLongs));
 }
Esempio n. 16
0
 public NodeStore(File file, File idFile, Config config, IdGeneratorFactory idGeneratorFactory, PageCache pageCache, LogProvider logProvider, DynamicArrayStore dynamicLabelStore, RecordFormats recordFormats, params OpenOption[] openOptions) : base(file, idFile, config, IdType.NODE, idGeneratorFactory, pageCache, logProvider, TYPE_DESCRIPTOR, recordFormats.Node(), NO_STORE_HEADER_FORMAT, recordFormats.StoreVersion(), openOptions)
 {
     this._dynamicLabelStore = dynamicLabelStore;
 }