Example #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void verifyCurrentLogAndNewLogLoadedFromFileSystem(RaftLog log, org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fileSystem, LogVerifier logVerifier) throws Exception
        private void VerifyCurrentLogAndNewLogLoadedFromFileSystem(RaftLog log, EphemeralFileSystemAbstraction fileSystem, LogVerifier logVerifier)
        {
            logVerifier.VerifyLog(log);
            logVerifier.VerifyLog(_logFactory.createBasedOn(FsRule.get()));
            fileSystem.Crash();
            logVerifier.VerifyLog(_logFactory.createBasedOn(FsRule.get()));
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailIfBothFilesAreEmpty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailIfBothFilesAreEmpty()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            File fileA = fileA();

            fsa.Create(fileA);

            File fileB = fileB();

            fsa.Create(fileB);

            StateRecoveryManager <long> manager = new StateRecoveryManager <long>(fsa, new LongMarshal());

            try
            {
                // when
                StateRecoveryManager.RecoveryStatus recoveryStatus = manager.Recover(fileA, fileB);
                fail();
            }
            catch (System.InvalidOperationException)
            {
                // then
                // expected
            }
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeIdempotent()
        public virtual void ShouldBeIdempotent()
        {
            // given
            EphemeralFileSystemAbstraction fsa = FileSystemRule.get();

            fsa.Mkdir(TestDir.directory());

            StateMarshal <ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal());

            DurableStateStorage <ReplicatedLockTokenState> storage = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance);

            using (Lifespan lifespan = new Lifespan(storage))
            {
                ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);

                MemberId memberA = member(0);
                MemberId memberB = member(1);

                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberA, 0), 3, r =>
                {
                });

                // when
                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberB, 1), 2, r =>
                {
                });

                // then
                assertEquals(memberA, stateMachine.CurrentToken().owner());
            }
        }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _databaseLayout = _testDirectory.databaseLayout();
            _storeDir       = _databaseLayout.databaseDirectory();
            _fileSystem     = _fileSystemRule.get();
            (new TestGraphDatabaseFactory()).setFileSystem(_fileSystem).newImpermanentDatabase(_storeDir).shutdown();
        }
Example #5
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()
        {
            _master         = mock(typeof(Master));
            _masterDelegate = new DelegateInvocationHandler <Master>(typeof(Master));
            _fs             = FileSystemRule.get();
            _fac            = new HaIdGeneratorFactory(_masterDelegate, NullLogProvider.Instance, mock(typeof(RequestContextFactory)), _fs, new CommunityIdTypeConfigurationProvider());
        }
Example #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReadDefragCountUsingStaticMethod() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReadDefragCountUsingStaticMethod()
        {
            EphemeralFileSystemAbstraction fs = Fsr.get();

            IdGeneratorImpl.CreateGenerator(fs, _file, 0, false);
            IdGeneratorImpl idGenerator = new IdGeneratorImpl(fs, _file, 1, 10000, false, IdType.Node, () => 0L);

            idGenerator.NextId();
            long a = idGenerator.NextId();

            idGenerator.NextId();
            long b = idGenerator.NextId();

            idGenerator.NextId();
            idGenerator.FreeId(a);
            idGenerator.FreeId(b);
            long expectedDefragCount = idGenerator.DefragCount;

            idGenerator.Dispose();

            long actualDefragCount = IdGeneratorImpl.ReadDefragCount(fs, _file);

            assertEquals(2, expectedDefragCount);
            assertEquals(expectedDefragCount, actualDefragCount);
        }
Example #7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnPreviouslyInactiveWhenOneFileFullAndOneEmpty() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnPreviouslyInactiveWhenOneFileFullAndOneEmpty()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            File         fileA   = fileA();
            StoreChannel channel = fsa.Create(fileA);

            FillUpAndForce(channel);

            File fileB = fileB();

            fsa.Create(fileB);

            StateRecoveryManager <long> manager = new StateRecoveryManager <long>(fsa, new LongMarshal());

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.state.StateRecoveryManager.RecoveryStatus recoveryStatus = manager.recover(fileA, fileB);
            StateRecoveryManager.RecoveryStatus recoveryStatus = manager.Recover(fileA, fileB);

            // then
            assertEquals(fileB, recoveryStatus.activeFile());
        }
Example #8
0
        /// <summary>
        /// Reading a node command might leave a node record which referred to
        /// labels in one or more dynamic records as marked as heavy even if that
        /// node already had references to dynamic records, changed in a transaction,
        /// but had no labels on that node changed within that same transaction.
        /// Now defensively only marks as heavy if there were one or more dynamic
        /// records provided when providing the record object with the label field
        /// value. This would give the opportunity to load the dynamic records the
        /// next time that record would be ensured heavy.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverNodeWithDynamicLabelRecords()
        public virtual void ShouldRecoverNodeWithDynamicLabelRecords()
        {
            // GIVEN
            _database = (new TestGraphDatabaseFactory()).setFileSystem(Fs).newImpermanentDatabase();
            Node node;

            Label[] labels = new Label[] { label("a"), label("b"), label("c"), label("d"), label("e"), label("f"), label("g"), label("h"), label("i"), label("j"), label("k") };
            using (Transaction tx = _database.beginTx())
            {
                node = _database.createNode(labels);
                tx.Success();
            }

            // WHEN
            using (Transaction tx = _database.beginTx())
            {
                node.SetProperty("prop", "value");
                tx.Success();
            }
            EphemeralFileSystemAbstraction snapshot = Fs.snapshot();

            _database.shutdown();
            _database = (new TestGraphDatabaseFactory()).setFileSystem(snapshot).newImpermanentDatabase();

            // THEN
            using (Transaction ignored = _database.beginTx())
            {
                node = _database.getNodeById(node.Id);
                foreach (Label label in labels)
                {
                    assertTrue(node.HasLabel(label));
                }
            }
        }
Example #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnTheFullFileAsPreviouslyInactiveWhenActiveContainsCorruptEntry() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnTheFullFileAsPreviouslyInactiveWhenActiveContainsCorruptEntry()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            File         fileA   = fileA();
            StoreChannel channel = fsa.Create(fileA);

            ByteBuffer buffer = WriteLong(42);

            channel.WriteAll(buffer);
            channel.Force(false);

            buffer.clear();
            buffer.putLong(101);                 // extraneous bytes
            buffer.flip();
            channel.WriteAll(buffer);
            channel.Force(false);

            File fileB = fileB();

            fsa.Create(fileB);

            StateRecoveryManager <long> manager = new StateRecoveryManager <long>(fsa, new LongMarshal());

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.state.StateRecoveryManager.RecoveryStatus recoveryStatus = manager.recover(fileA, fileB);
            StateRecoveryManager.RecoveryStatus recoveryStatus = manager.Recover(fileA, fileB);

            // then
            assertEquals(fileB, recoveryStatus.activeFile());
        }
Example #10
0
 public MonitorAdapterAnonymousInnerClass(ConstraintRecoveryIT outerInstance, EphemeralFileSystemAbstraction fs, EphemeralFileSystemAbstraction[] storeInNeedOfRecovery, AtomicBoolean monitorCalled)
 {
     this.outerInstance          = outerInstance;
     this._fs                    = fs;
     this._storeInNeedOfRecovery = storeInNeedOfRecovery;
     this._monitorCalled         = monitorCalled;
 }
Example #11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setup()
        public virtual void Setup()
        {
            _fileSystemAbstraction = FsRule.get();
            _storeFile             = TestDirectory.databaseLayout().propertyStore();
            _idFile = TestDirectory.databaseLayout().idPropertyStore();

            _fileSystemAbstraction.mkdir(_storeFile.ParentFile);
        }
Example #12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createLogFile(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fsa, long prevFileLastIndex, long fileNameVersion, long headerVersion, long prevIndex, long prevTerm) throws java.io.IOException
        private void CreateLogFile(EphemeralFileSystemAbstraction fsa, long prevFileLastIndex, long fileNameVersion, long headerVersion, long prevIndex, long prevTerm)
        {
            StoreChannel             channel = fsa.Open(_fileNames.getForVersion(fileNameVersion), OpenMode.READ_WRITE);
            PhysicalFlushableChannel writer  = new PhysicalFlushableChannel(channel);

            _headerMarshal.marshal(new SegmentHeader(prevFileLastIndex, headerVersion, prevIndex, prevTerm), writer);
            writer.PrepareForFlush().flush();
            channel.close();
        }
Example #13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldClearFileOnFirstUse() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldClearFileOnFirstUse()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            int rotationCount = 10;

            DurableStateStorage <AtomicInteger> storage = new DurableStateStorage <AtomicInteger>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), rotationCount, NullLogProvider.Instance);
            int largestValueWritten = 0;

            using (Lifespan lifespan = new Lifespan(storage))
            {
                for ( ; largestValueWritten < rotationCount * 2; largestValueWritten++)
                {
                    storage.PersistStoreData(new AtomicInteger(largestValueWritten));
                }
            }

            // now both files are full. We reopen, then write some more.
            storage = _lifeRule.add(new DurableStateStorage <>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), rotationCount, NullLogProvider.Instance));

            storage.PersistStoreData(new AtomicInteger(largestValueWritten++));
            storage.PersistStoreData(new AtomicInteger(largestValueWritten++));
            storage.PersistStoreData(new AtomicInteger(largestValueWritten));

            /*
             * We have written stuff in fileA but not gotten to the end (resulting in rotation). The largestValueWritten
             * should nevertheless be correct
             */
            ByteBuffer   forReadingBackIn = ByteBuffer.allocate(10_000);
            StoreChannel lastWrittenTo    = fsa.Open(StateFileA(), OpenMode.READ);

            lastWrittenTo.read(forReadingBackIn);
            forReadingBackIn.flip();

            AtomicInteger lastRead = null;

            while (true)
            {
                try
                {
                    lastRead = new AtomicInteger(forReadingBackIn.Int);
                }
                catch (BufferUnderflowException)
                {
                    break;
                }
            }

            // then
            assertNotNull(lastRead);
            assertEquals(largestValueWritten, lastRead.get());
        }
Example #14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void openingThroughStoreAccessShouldNotTriggerRecovery() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void OpeningThroughStoreAccessShouldNotTriggerRecovery()
        {
            using (EphemeralFileSystemAbstraction snapshot = ProduceUncleanStore())
            {
                assertTrue("Store should be unclean", IsUnclean(snapshot));

                PageCache pageCache = PageCacheRule.getPageCache(snapshot);
                (new StoreAccess(snapshot, pageCache, TestDirectory.databaseLayout(), Config.defaults())).initialize().close();
                assertTrue("Store should be unclean", IsUnclean(snapshot));
            }
        }
Example #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void createFile(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fsa, java.io.File name, int bufferSize) throws java.io.IOException
        private void CreateFile(EphemeralFileSystemAbstraction fsa, File name, int bufferSize)
        {
            StoreChannel storeChannel = fsa.Open(name, OpenMode.READ_WRITE);
            ByteBuffer   buffer       = ByteBuffer.allocate(bufferSize);

            for (int i = 0; i < bufferSize; i++)
            {
                buffer.put(( sbyte )i);
            }
            buffer.flip();
            storeChannel.WriteAll(buffer);
            storeChannel.close();
        }
Example #16
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writeSomeGarbage(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fsa, java.io.File file) throws java.io.IOException
        private void WriteSomeGarbage(EphemeralFileSystemAbstraction fsa, File file)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.StoreChannel channel = fsa.open(file, org.neo4j.io.fs.OpenMode.READ_WRITE);
            StoreChannel channel = fsa.Open(file, OpenMode.READ_WRITE);
            ByteBuffer   buffer  = ByteBuffer.allocate(4);

            buffer.putInt(9876);
            buffer.flip();
            channel.WriteAll(buffer);
            channel.Force(false);
            channel.close();
        }
Example #17
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.causalclustering.core.consensus.log.RaftLog createRaftLog() throws Exception
        private RaftLog CreateRaftLog()
        {
            File directory = new File(RAFT_LOG_DIRECTORY_NAME);
            FileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction();

            fileSystem.Mkdir(directory);

            LogProvider            logProvider     = Instance;
            CoreLogPruningStrategy pruningStrategy = (new CoreLogPruningStrategyFactory("1 entries", logProvider)).NewInstance();
            SegmentedRaftLog       newRaftLog      = new SegmentedRaftLog(fileSystem, directory, 1, new DummyRaftableContentSerializer(), logProvider, 8, Clocks.fakeClock(), new OnDemandJobScheduler(), pruningStrategy);

            newRaftLog.Start();
            return(newRaftLog);
        }
Example #18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void twoUncleanInARow() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TwoUncleanInARow()
        {
            File databaseDir = TestDirectory.databaseDir();

            using (EphemeralFileSystemAbstraction snapshot = ProduceUncleanStore(Fs.get(), databaseDir))
            {
                using (EphemeralFileSystemAbstraction snapshot2 = ProduceUncleanStore(snapshot, databaseDir))
                {
                    GraphDatabaseAPI db = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(ProduceUncleanStore(snapshot2, databaseDir)).newImpermanentDatabase(databaseDir);
                    assertThat(Properties(db), inTx(db, hasProperty("prop").withValue("Some value")));
                    Db.shutdown();
                }
            }
        }
Example #19
0
        private EphemeralFileSystemAbstraction ProduceUncleanStore()
        {
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(Fs.get()).newImpermanentDatabase(TestDirectory.databaseDir());

            using (Transaction tx = Db.beginTx())
            {
                Db.createNode();
                tx.Success();
            }
            EphemeralFileSystemAbstraction snapshot = Fs.get().snapshot();

            Db.shutdown();
            return(snapshot);
        }
Example #20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldMaintainStateGivenAnEmptyInitialStore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldMaintainStateGivenAnEmptyInitialStore()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            DurableStateStorage <AtomicInteger> storage = _lifeRule.add(new DurableStateStorage <AtomicInteger>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), 100, NullLogProvider.Instance));

            // when
            storage.PersistStoreData(new AtomicInteger(99));

            // then
            assertEquals(4, fsa.GetFileSize(StateFileA()));
        }
Example #21
0
        private EphemeralFileSystemAbstraction ProduceUncleanStore(EphemeralFileSystemAbstraction fileSystem, File storeDir)
        {
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(fileSystem).newImpermanentDatabase(storeDir);
            Transaction          tx = Db.beginTx();
            Node node = Db.createNode();

            node.SetProperty("name", "Something");
            Properties(( GraphDatabaseAPI )db).setProperty("prop", "Some value");
            tx.Success();
            tx.Close();
            EphemeralFileSystemAbstraction snapshot = fileSystem.Snapshot();

            Db.shutdown();
            return(snapshot);
        }
Example #22
0
        private static FileSystemAbstraction CreateSomeDataAndCrash(File store, EphemeralFileSystemAbstraction fileSystem, Config config)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService db = new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fileSystem).newImpermanentDatabaseBuilder(store).setConfig(config.getRaw()).newGraphDatabase();
            GraphDatabaseService db = (new TestGraphDatabaseFactory()).setFileSystem(fileSystem).newImpermanentDatabaseBuilder(store).setConfig(config.Raw).newGraphDatabase();

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

            EphemeralFileSystemAbstraction snapshot = fileSystem.Snapshot();

            Db.shutdown();
            return(snapshot);
        }
Example #23
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writeSomeLongsIn(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fsa, java.io.File file, long... longs) throws java.io.IOException
        private void WriteSomeLongsIn(EphemeralFileSystemAbstraction fsa, File file, params long[] longs)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.io.fs.StoreChannel channel = fsa.open(file, org.neo4j.io.fs.OpenMode.READ_WRITE);
            StoreChannel channel = fsa.Open(file, OpenMode.READ_WRITE);
            ByteBuffer   buffer  = ByteBuffer.allocate(longs.Length * 8);

            foreach (long aLong in longs)
            {
                buffer.putLong(aLong);
            }

            buffer.flip();
            channel.WriteAll(buffer);
            channel.Force(false);
            channel.close();
        }
Example #24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPersistAndRecoverState() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPersistAndRecoverState()
        {
            // given
            EphemeralFileSystemAbstraction fsa = FileSystemRule.get();

            fsa.Mkdir(TestDir.directory());

            StateMarshal <ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal());

            MemberId memberA = member(0);
            MemberId memberB = member(1);
            int      candidateId;

            DurableStateStorage <ReplicatedLockTokenState> storage = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance);

            using (Lifespan lifespan = new Lifespan(storage))
            {
                ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);

                // when
                candidateId = 0;
                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberA, candidateId), 0, r =>
                {
                });
                candidateId = 1;
                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberB, candidateId), 1, r =>
                {
                });

                stateMachine.Flush();
                fsa.Crash();
            }

            // then
            DurableStateStorage <ReplicatedLockTokenState> storage2 = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance);

            using (Lifespan lifespan = new Lifespan(storage2))
            {
                ReplicatedLockTokenState initialState = storage2.InitialState;

                assertEquals(memberB, initialState.Get().owner());
                assertEquals(candidateId, initialState.Get().id());
            }
        }
Example #25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStoreAByteAtBoundary() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldStoreAByteAtBoundary()
        {
            using (EphemeralFileSystemAbstraction fs = new EphemeralFileSystemAbstraction())
            {
                File workFile = TmpDir.file("a");
                fs.Mkdirs(TmpDir.directory());
                Stream @out = fs.OpenAsOutputStream(workFile, false);

                // When I write a byte[] that is larger than the internal buffer in
                // ChannelOutputStream..
                sbyte[] b = new sbyte[8097];
                b[b.Length - 1] = 7;
                @out.Write(b, 0, b.Length);
                @out.Flush();

                // Then it should get cleanly written and be readable
                Stream @in = fs.OpenAsInputStream(workFile);
                @in.skip(8096);
                assertEquals(7, @in.Read());
            }
        }
Example #26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleWritesProperlyAfterRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleWritesProperlyAfterRecovery()
        {
            // Given
            EphemeralFileSystemAbstraction fs = FsRule.get();
            GraphDatabaseService           db = NewDB(fs);

            long node1 = CreateNode(db);

            // And given the power goes out
            using (EphemeralFileSystemAbstraction crashedFs = fs.Snapshot())
            {
                Db.shutdown();
                db = NewDB(crashedFs);

                long node2 = CreateNode(db);
                Db.shutdown();

                // Then the logical log should be in sync
                File logFile = TestDirectory.databaseLayout().file(TransactionLogFiles.DEFAULT_NAME + ".0");
                assertThat(logEntries(crashedFs, logFile), containsExactly(startEntry(-1, -1), commandEntry(node1, typeof(NodeCommand)), commandEntry(StatementConstants.ANY_LABEL, typeof(NodeCountsCommand)), commitEntry(2), startEntry(-1, -1), commandEntry(node2, typeof(NodeCommand)), commandEntry(StatementConstants.ANY_LABEL, typeof(NodeCountsCommand)), commitEntry(3), checkPoint(new LogPosition(0, 250))));
            }
        }
Example #27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverFromPartiallyWrittenEntriesInBothFiles() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverFromPartiallyWrittenEntriesInBothFiles()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            StateRecoveryManager <long> manager = new StateRecoveryManager <long>(fsa, new LongMarshal());

            WriteSomeLongsIn(fsa, FileA(), 3, 4);
            WriteSomeLongsIn(fsa, FileB(), 5, 6);
            WriteSomeGarbage(fsa, FileA());
            WriteSomeGarbage(fsa, FileB());

            // when
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.causalclustering.core.state.StateRecoveryManager.RecoveryStatus recovered = manager.recover(fileA(), fileB());
            StateRecoveryManager.RecoveryStatus recovered = manager.Recover(FileA(), FileB());

            // then
            assertEquals(FileA(), recovered.activeFile());
            assertEquals(6L, recovered.recoveredState());
        }
Example #28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRotateToOtherStoreFileAfterSufficientEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRotateToOtherStoreFileAfterSufficientEntries()
        {
            // given
            EphemeralFileSystemAbstraction fsa = _fileSystemRule.get();

            fsa.Mkdir(_testDir.directory());

            const int numberOfEntriesBeforeRotation     = 100;
            DurableStateStorage <AtomicInteger> storage = _lifeRule.add(new DurableStateStorage <AtomicInteger>(fsa, _testDir.directory(), "state", new AtomicIntegerMarshal(), numberOfEntriesBeforeRotation, NullLogProvider.Instance));

            // when
            for (int i = 0; i < numberOfEntriesBeforeRotation; i++)
            {
                storage.PersistStoreData(new AtomicInteger(i));
            }

            // Force the rotation
            storage.PersistStoreData(new AtomicInteger(9999));

            // then
            assertEquals(4, fsa.GetFileSize(StateFileB()));
            assertEquals(numberOfEntriesBeforeRotation * 4, fsa.GetFileSize(StateFileA()));
        }
Example #29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void doBefore()
        public virtual void DoBefore()
        {
            _fs = _fsRule.get();
        }
Example #30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails()
        public virtual void ShouldHaveAvailableOrphanedConstraintIndexIfUniqueConstraintCreationFails()
        {
            // given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction fs = fileSystemRule.get();
            EphemeralFileSystemAbstraction fs = FileSystemRule.get();

            fs.Mkdir(new File("/tmp"));
            File pathToDb = new File("/tmp/bar2");

            TestGraphDatabaseFactory dbFactory = new TestGraphDatabaseFactory();

            dbFactory.FileSystem = fs;

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction[1];
            EphemeralFileSystemAbstraction[] storeInNeedOfRecovery = new EphemeralFileSystemAbstraction[1];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean monitorCalled = new java.util.concurrent.atomic.AtomicBoolean(false);
            AtomicBoolean monitorCalled = new AtomicBoolean(false);

            Monitors monitors = new Monitors();

            monitors.AddMonitorListener(new MonitorAdapterAnonymousInnerClass(this, fs, storeInNeedOfRecovery, monitorCalled));
            dbFactory.Monitors = monitors;

            // This test relies on behaviour that is specific to the Lucene populator, where uniqueness is controlled
            // after index has been populated, which is why we're using NATIVE20 and index booleans (they end up in Lucene)
            _db = ( GraphDatabaseAPI )dbFactory.NewImpermanentDatabaseBuilder(pathToDb).setConfig(default_schema_provider, NATIVE20.providerName()).newGraphDatabase();

            using (Transaction tx = _db.beginTx())
            {
                for (int i = 0; i < 2; i++)
                {
                    _db.createNode(_label).setProperty(KEY, true);
                }

                tx.Success();
            }

            try
            {
                using (Transaction tx = _db.beginTx())
                {
                    _db.schema().constraintFor(_label).assertPropertyIsUnique(KEY).create();
                    fail("Should have failed with ConstraintViolationException");
                    tx.Success();
                }
            }
            catch (ConstraintViolationException)
            {
            }

            _db.shutdown();

            assertTrue(monitorCalled.get());

            // when
            dbFactory            = new TestGraphDatabaseFactory();
            dbFactory.FileSystem = storeInNeedOfRecovery[0];
            _db = ( GraphDatabaseAPI )dbFactory.NewImpermanentDatabase(pathToDb);

            // then
            using (Transaction ignore = _db.beginTx())
            {
                _db.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
            }

            using (Transaction ignore = _db.beginTx())
            {
                assertEquals(2, Iterables.count(_db.AllNodes));
            }

            using (Transaction ignore = _db.beginTx())
            {
                assertEquals(0, Iterables.count(Iterables.asList(_db.schema().Constraints)));
            }

            using (Transaction ignore = _db.beginTx())
            {
                IndexDefinition orphanedConstraintIndex = single(_db.schema().Indexes);
                assertEquals(_label.name(), single(orphanedConstraintIndex.Labels).name());
                assertEquals(KEY, single(orphanedConstraintIndex.PropertyKeys));
            }

            _db.shutdown();
        }