Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void firstRecordOtherThanZeroIfNotFirst()
        public virtual void FirstRecordOtherThanZeroIfNotFirst()
        {
            File             storeDir = TestDirectory.databaseDir();
            GraphDatabaseAPI db       = ( GraphDatabaseAPI )_factory.newImpermanentDatabase(storeDir);
            Transaction      tx       = Db.beginTx();
            Node             node     = Db.createNode();

            node.SetProperty("name", "Yo");
            tx.Success();
            tx.Close();
            Db.shutdown();

            db = ( GraphDatabaseAPI )_factory.newImpermanentDatabase(storeDir);
            tx = Db.beginTx();
            Properties(db).setProperty("test", "something");
            tx.Success();
            tx.Close();
            Db.shutdown();

            Config       config       = Config.defaults();
            StoreFactory storeFactory = new StoreFactory(TestDirectory.databaseLayout(), config, new DefaultIdGeneratorFactory(Fs.get()), PageCacheRule.getPageCache(Fs.get()), Fs.get(), NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);
            NeoStores    neoStores    = storeFactory.OpenAllNeoStores();
            long         prop         = neoStores.MetaDataStore.GraphNextProp;

            assertTrue(prop != 0);
            neoStores.Close();
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void verifyDynamicSizedStoresCanRebuildIdGeneratorSlowly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void VerifyDynamicSizedStoresCanRebuildIdGeneratorSlowly()
        {
            // Given we have a store ...
            Config config = Config.defaults(GraphDatabaseSettings.rebuild_idgenerators_fast, "false");

            StoreFactory       storeFactory = new StoreFactory(_testDirectory.databaseLayout(), config, new DefaultIdGeneratorFactory(_fs), PageCacheRule.getPageCache(_fs), _fs, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);
            NeoStores          neoStores    = storeFactory.OpenAllNeoStores(true);
            DynamicStringStore store        = neoStores.PropertyStore.StringStore;

            // ... that contain a number of records ...
            DynamicRecord record = new DynamicRecord(1);

            record.SetInUse(true, PropertyType.String.intValue());
            int highestId = 50;

            for (int i = 1; i <= highestId; i++)                 // id '0' is the dynamic store header
            {
                assertThat(store.NextId(), @is((long)i));
                record.Id = i;
                StringBuilder sb = new StringBuilder(i);
                for (int j = 0; j < i; j++)
                {
                    sb.Append('a');
                }
                record.Data = sb.ToString().GetBytes(StandardCharsets.UTF_16);
                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();

            // 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, 51L));
            neoStores.Close();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGrowAFileWhileContinuingToMemoryMapNewRegions()
        public virtual void ShouldGrowAFileWhileContinuingToMemoryMapNewRegions()
        {
            // don't run on windows because memory mapping doesn't work properly there
            assumeTrue(!SystemUtils.IS_OS_WINDOWS);

            // given
            const int numberOfRecords = 1000000;

            Config config = Config.defaults(pagecache_memory, MmapSize(numberOfRecords, NodeRecordFormat.RECORD_SIZE));
            FileSystemAbstraction     fileSystemAbstraction = _fileSystemRule.get();
            DefaultIdGeneratorFactory idGeneratorFactory    = new DefaultIdGeneratorFactory(fileSystemAbstraction);
            PageCache    pageCache    = _pageCacheRule.getPageCache(fileSystemAbstraction, config);
            StoreFactory storeFactory = new StoreFactory(_testDirectory.databaseLayout(), config, idGeneratorFactory, pageCache, fileSystemAbstraction, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            NeoStores neoStores = storeFactory.OpenAllNeoStores(true);
            NodeStore nodeStore = neoStores.NodeStore;

            // when
            int  iterations = 2 * numberOfRecords;
            long startingId = nodeStore.NextId();
            long nodeId     = startingId;

            for (int i = 0; i < iterations; i++)
            {
                NodeRecord record = new NodeRecord(nodeId, false, i, 0);
                record.InUse = true;
                nodeStore.UpdateRecord(record);
                nodeId = nodeStore.NextId();
            }

            // then
            NodeRecord record = new NodeRecord(0, false, 0, 0);

            for (int i = 0; i < iterations; i++)
            {
                record.Id = startingId + i;
                nodeStore.GetRecord(i, record, NORMAL);
                assertTrue("record[" + i + "] should be in use", record.InUse());
                assertThat("record[" + i + "] should have nextRelId of " + i, record.NextRel, @is(( long )i));
            }

            neoStores.Close();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustCloseAllStoresIfNeoStoresFailToOpen()
        public virtual void MustCloseAllStoresIfNeoStoresFailToOpen()
        {
            PageCache              pageCache      = Rules.pageCache();
            DatabaseLayout         databaseLayout = Rules.directory().databaseLayout();
            Config                 config         = Config.defaults();
            FileSystemAbstraction  fs             = Rules.fileSystem();
            IdGeneratorFactory     idGenFactory   = new DefaultIdGeneratorFactory(fs);
            LogProvider            logProvider    = NullLogProvider.Instance;
            VersionContextSupplier versions       = EmptyVersionContextSupplier.EMPTY;
            RecordFormats          formats        = Standard.LATEST_RECORD_FORMATS;

            (new RecordFormatPropertyConfigurator(formats, config)).configure();
            bool create = true;

            StoreType[]  storeTypes  = StoreType.values();
            OpenOption[] openOptions = new OpenOption[0];
            NeoStores    neoStores   = new NeoStores(databaseLayout, config, idGenFactory, pageCache, logProvider, fs, versions, formats, create, storeTypes, openOptions);
            File         schemaStore = neoStores.SchemaStore.StorageFile;

            neoStores.Close();

            // Make the schema store inaccessible, to sabotage the next initialisation we'll do.
            assumeTrue(schemaStore.setReadable(false));
            assumeTrue(schemaStore.setWritable(false));

            try
            {
                // This should fail due to the permissions we changed above.
                // And when it fails, the already-opened stores should be closed.
                new NeoStores(databaseLayout, config, idGenFactory, pageCache, logProvider, fs, versions, formats, create, storeTypes, openOptions);
                fail("Opening NeoStores should have thrown.");
            }
            catch (Exception)
            {
            }

            // We verify that the successfully opened stores were closed again by the failed NeoStores open,
            // by closing the page cache, which will throw if not all files have been unmapped.
            pageCache.Close();
        }