Esempio n. 1
0
        private void FlushNeoStoreOnly()
        {
            NeoStores     neoStores     = (( GraphDatabaseAPI )_db).DependencyResolver.resolveDependency(typeof(RecordStorageEngine)).testAccessNeoStores();
            MetaDataStore metaDataStore = neoStores.MetaDataStore;

            metaDataStore.Flush();
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void prepareNeoStoreFile(String storeVersion) throws java.io.IOException
        private void PrepareNeoStoreFile(string storeVersion)
        {
            File neoStoreFile = CreateNeoStoreFile();
            long value        = MetaDataStore.versionStringToLong(storeVersion);

            MetaDataStore.setRecord(PageCacheRule.getPageCache(FsRule.get()), neoStoreFile, STORE_VERSION, value);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void extractTransactionalInformationFromLogs(String path, java.io.File customLogLocation, org.neo4j.io.layout.DatabaseLayout databaseLayout, java.io.File storeDir) throws java.io.IOException
        private void ExtractTransactionalInformationFromLogs(string path, File customLogLocation, DatabaseLayout databaseLayout, File storeDir)
        {
            LogService logService = new SimpleLogService(NullLogProvider.Instance, NullLogProvider.Instance);
            File       neoStore   = databaseLayout.MetadataStore();

            GraphDatabaseService database = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(storeDir).setConfig(logical_logs_location, path).newGraphDatabase();

            for (int i = 0; i < 10; i++)
            {
                using (Transaction transaction = database.BeginTx())
                {
                    Node node = database.CreateNode();
                    transaction.Success();
                }
            }
            database.Shutdown();

            MetaDataStore.setRecord(_pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT);
            Config        config      = Config.defaults(logical_logs_location, path);
            StoreMigrator migrator    = new StoreMigrator(_fileSystemRule.get(), _pageCache, config, logService, _jobScheduler);
            LogPosition   logPosition = migrator.ExtractTransactionLogPosition(neoStore, databaseLayout, 100);

            File[] logFiles = customLogLocation.listFiles();
            assertNotNull(logFiles);
            assertEquals(0, logPosition.LogVersion);
            assertEquals(logFiles[0].length(), logPosition.ByteOffset);
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static long readLogVersion(org.neo4j.io.pagecache.PageCache pageCache, java.io.File neoStore) throws java.io.IOException
        private static long ReadLogVersion(PageCache pageCache, File neoStore)
        {
            try
            {
                return(MetaDataStore.getRecord(pageCache, neoStore, MetaDataStore.Position.LOG_VERSION));
            }
            catch (NoSuchFileException)
            {
                return(0);
            }
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteNewFileWhenExistingFileHasZeroLength() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteNewFileWhenExistingFileHasZeroLength()
        {
            // Given
            _file.createNewFile();

            // When
            IndexProviderStore store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong("3.5"), false);

            // Then
            assertTrue(_fileSystem.getFileSize(_file) > 0);
            store.Close();
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = IllegalArgumentException.class) public void shouldThrowWhenTryingToCreateFileThatAlreadyExists()
        public virtual void ShouldThrowWhenTryingToCreateFileThatAlreadyExists()
        {
            // Given
            FileSystemAbstraction fs = mock(typeof(FileSystemAbstraction));

            when(fs.FileExists(_file)).thenReturn(false).thenReturn(true);
            when(fs.GetFileSize(_file)).thenReturn(42L);

            // When
            new IndexProviderStore(_file, fs, MetaDataStore.versionStringToLong("3.5"), false);

            // Then
            // exception is thrown
        }
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 shouldPropagateIOExceptions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPropagateIOExceptions()
        {
            // Given
            TransactionFailureException exceptionThrown = null;

            File storeDir = TestDirectory.storeDir();
            LimitedFileSystemGraphDatabase db = new LimitedFileSystemGraphDatabase(storeDir);

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }

            long logVersion = Db.DependencyResolver.resolveDependency(typeof(LogVersionRepository)).CurrentLogVersion;

            Db.runOutOfDiskSpaceNao();

            // When
            try
            {
                using (Transaction tx = Db.beginTx())
                {
                    Db.createNode();
                    tx.Success();
                }
            }
            catch (TransactionFailureException e)
            {
                exceptionThrown = e;
            }
            finally
            {
                assertNotNull("Expected tx finish to throw TransactionFailureException when filesystem is full.", exceptionThrown);
                assertTrue(Exceptions.contains(exceptionThrown, typeof(IOException)));
            }

            Db.somehowGainMoreDiskSpace();               // to help shutting down the db
            Db.shutdown();

            PageCache pageCache = PageCacheRule.getPageCache(Db.FileSystem);
            File      neoStore  = TestDirectory.databaseLayout().metadataStore();

            assertEquals(logVersion, MetaDataStore.getRecord(pageCache, neoStore, MetaDataStore.Position.LOG_VERSION));
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.kernel.impl.store.NotCurrentStoreVersionException.class) public void shouldFailToGoBackToOlderVersionEvenIfAllowUpgrade()
        public virtual void ShouldFailToGoBackToOlderVersionEvenIfAllowUpgrade()
        {
            string newerVersion = "3.5";
            string olderVersion = "3.1";

            try
            {
                IndexProviderStore store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong(newerVersion), true);
                store.Close();
                store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong(olderVersion), true);
            }
            catch (NotCurrentStoreVersionException e)
            {
                assertTrue(e.Message.contains(newerVersion));
                assertTrue(e.Message.contains(olderVersion));
                throw e;
            }
        }
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 shouldReportFileWithCorrectVersion() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReportFileWithCorrectVersion()
        {
            // given
            File      neoStore  = EmptyFile(_fileSystemRule.get());
            long      v1        = MetaDataStore.versionStringToLong("V1");
            PageCache pageCache = _pageCacheRule.getPageCache(_fileSystemRule.get());

            MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.STORE_VERSION, v1);
            StoreVersionCheck storeVersionCheck = new StoreVersionCheck(pageCache);

            // when
            StoreVersionCheck.Result result = storeVersionCheck.HasVersion(neoStore, "V1");

            // then
            assertTrue(result.Outcome.Successful);
            assertEquals(StoreVersionCheck.Result.Outcome.Ok, result.Outcome);
            assertNull(result.ActualVersion);
        }
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 shouldFailUpgradeIfNotAllowed()
        public virtual void ShouldFailUpgradeIfNotAllowed()
        {
            IndexProviderStore store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong("3.1"), true);

            store.Close();
            store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong("3.1"), false);
            store.Close();
            try
            {
                new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong("3.5"), false);
                fail("Shouldn't be able to upgrade there");
            }
            catch (UpgradeNotAllowedByConfigurationException)
            {               // Good
            }
            store = new IndexProviderStore(_file, _fileSystem, MetaDataStore.versionStringToLong("3.5"), true);
            assertEquals("3.5", MetaDataStore.versionLongToString(store.IndexVersion));
            store.Close();
        }
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 shouldForceChannelAfterWritingMetadata() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldForceChannelAfterWritingMetadata()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.StoreChannel[] channelUsedToCreateFile = {null};
            StoreChannel[] channelUsedToCreateFile = new StoreChannel[] { null };

            FileSystemAbstraction fs = spy(_fileSystem);
            StoreChannel          tempChannel;

            when(tempChannel = fs.Open(_file, OpenMode.READ_WRITE)).then(ignored =>
            {
                StoreChannel channel = _fileSystem.open(_file, OpenMode.READ_WRITE);
                if (channelUsedToCreateFile[0] == null)
                {
                    StoreChannel channelSpy    = spy(channel);
                    channelUsedToCreateFile[0] = channelSpy;
                    channel = channelSpy;
                }
                return(channel);
            });

            // Doing the FSA spying above, calling fs.open, actually invokes that method and so a channel
            // is opened. We put that in tempChannel and close it before deleting the file below.
            tempChannel.close();
            fs.DeleteFile(_file);

            // When
            IndexProviderStore store = new IndexProviderStore(_file, fs, MetaDataStore.versionStringToLong("3.5"), false);

            // Then
            StoreChannel channel = channelUsedToCreateFile[0];

            verify(channel).writeAll(any(typeof(ByteBuffer)), eq(0L));
            verify(channel).force(true);
            verify(channel).close();
            verifyNoMoreInteractions(channel);
            store.Close();
        }
Esempio n. 12
0
 public static StoreId NewStoreIdForCurrentVersion(long creationTime, long randomId, long upgradeTime, long upgradeId)
 {
     return(new StoreId(creationTime, randomId, MetaDataStore.versionStringToLong(_format.storeVersion()), upgradeTime, upgradeId));
 }
Esempio n. 13
0
 private static long CurrentStoreVersionAsLong()
 {
     return(MetaDataStore.versionStringToLong(_format.storeVersion()));
 }
Esempio n. 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStopDatabaseWhenOutOfDiskSpace() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStopDatabaseWhenOutOfDiskSpace()
        {
            // Given
            TransactionFailureException expectedCommitException = null;
            TransactionFailureException expectedStartException  = null;
            File storeDir = TestDirectory.absolutePath();
            LimitedFileSystemGraphDatabase db = Cleanup.add(new LimitedFileSystemGraphDatabase(storeDir));

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }

            long logVersion = Db.DependencyResolver.resolveDependency(typeof(LogVersionRepository)).CurrentLogVersion;

            Db.runOutOfDiskSpaceNao();

            try
            {
                using (Transaction tx = Db.beginTx())
                {
                    Db.createNode();
                    tx.Success();
                }
            }
            catch (TransactionFailureException e)
            {
                expectedCommitException = e;
            }
            finally
            {
                assertNotNull("Expected tx finish to throw TransactionFailureException when filesystem is full.", expectedCommitException);
            }

            // When
            try
            {
                using (Transaction transaction = Db.beginTx())
                {
                    fail("Expected tx begin to throw TransactionFailureException when tx manager breaks.");
                }
            }
            catch (TransactionFailureException e)
            {
                expectedStartException = e;
            }
            finally
            {
                assertNotNull("Expected tx begin to throw TransactionFailureException when tx manager breaks.", expectedStartException);
            }

            // Then
            Db.somehowGainMoreDiskSpace();               // to help shutting down the db
            Db.shutdown();

            PageCache pageCache = PageCacheRule.getPageCache(Db.FileSystem);
            File      neoStore  = TestDirectory.databaseLayout().metadataStore();

            assertEquals(logVersion, MetaDataStore.getRecord(pageCache, neoStore, MetaDataStore.Position.LOG_VERSION));
        }
Esempio n. 15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void prepareEmpty23Database() throws java.io.IOException
        private void PrepareEmpty23Database()
        {
            (new TestGraphDatabaseFactory()).newEmbeddedDatabase(_storeDir).shutdown();
            _fileSystem.deleteFile(_nativeLabelIndex);
            MetaDataStore.setRecord(_pageCache, _databaseLayout.metadataStore(), MetaDataStore.Position.STORE_VERSION, versionStringToLong(StandardV2_3.STORE_VERSION));
        }