Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateTransactionWithCustomTimeoutWithoutConfiguredDefault()
		 public virtual void TerminateTransactionWithCustomTimeoutWithoutConfiguredDefault()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithoutTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  using ( Transaction transaction = database.BeginTx( 27, TimeUnit.SECONDS ) )
			  {
					_fakeClock.forward( 26, TimeUnit.SECONDS );
					timeoutMonitor.Run();
					database.CreateNode();
					transaction.Failure();
			  }

			  try
			  {
					  using ( Transaction transaction = database.BeginTx( 27, TimeUnit.SECONDS ) )
					  {
						_fakeClock.forward( 28, TimeUnit.SECONDS );
						timeoutMonitor.Run();
						database.CreateNode();
						fail( "Transaction should be already terminated." );
					  }
			  }
			  catch ( TransactionTerminatedException e )
			  {
					assertThat( e.Message, startsWith( "The transaction has been terminated." ) );
			  }

			  AssertDatabaseDoesNotHaveNodes( database );
		 }
Example #2
0
 private static void AddData(GraphDatabaseAPI graphDb)
 {
     using (Transaction tx = graphDb.BeginTx())
     {
         Node node = graphDb.CreateNode();
         node.AddLabel(Label);
         node.SetProperty(PROP_NAME, "Neo");
         node.SetProperty(PROP, GlobalRandom.NextDouble * 10000);
         graphDb.CreateNode().createRelationshipTo(node, RelationshipType.withName("KNOWS"));
         tx.Success();
     }
 }
Example #3
0
 private static void GenerateTransaction(GraphDatabaseAPI database)
 {
     using (Transaction transaction = database.BeginTx())
     {
         Node startNode = database.CreateNode(Label.label("startNode"));
         startNode.SetProperty("key", "value");
         Node endNode = database.CreateNode(Label.label("endNode"));
         endNode.SetProperty("key", "value");
         startNode.CreateRelationshipTo(endNode, RelationshipType.withName("connects"));
         transaction.Success();
     }
 }
Example #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateLongRunningTransaction()
		 public virtual void TerminateLongRunningTransaction()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  try
			  {
					  using ( Transaction transaction = database.BeginTx() )
					  {
						_fakeClock.forward( 3, TimeUnit.SECONDS );
						transaction.Success();
						timeoutMonitor.Run();
						database.CreateNode();
						fail( "Transaction should be already terminated." );
					  }
			  }
			  catch ( TransactionTerminatedException e )
			  {
					assertThat( e.Message, startsWith( "The transaction has been terminated." ) );
					assertEquals( e.Status(), Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut );
			  }

			  AssertDatabaseDoesNotHaveNodes( database );
		 }
Example #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void crashAndRebuildSlowWithDynamicStringDeletions() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CrashAndRebuildSlowWithDynamicStringDeletions()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.internal.GraphDatabaseAPI db = (org.neo4j.kernel.internal.GraphDatabaseAPI) new org.neo4j.test.TestGraphDatabaseFactory().setFileSystem(fs.get()).newImpermanentDatabaseBuilder(testDir.databaseDir()).setConfig(org.neo4j.graphdb.factory.GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase();
            GraphDatabaseAPI           db                 = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(Fs.get()).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.record_id_batch_size, "1").newGraphDatabase();
            IList <long>               deletedNodeIds     = ProduceNonCleanDefraggedStringStore(db);
            IDictionary <IdType, long> highIdsBeforeCrash = GetHighIds(db);

            // Make sure all of our changes are actually written to the files, since any background flushing could
            // mess up the check-sums in non-deterministic ways
            Db.DependencyResolver.resolveDependency(typeof(PageCache)).flushAndForce();

            long checksumBefore  = Fs.get().checksum();
            long checksumBefore2 = Fs.get().checksum();

            assertThat(checksumBefore, Matchers.equalTo(checksumBefore2));

            EphemeralFileSystemAbstraction snapshot = Fs.snapshot(Db.shutdown);

            long snapshotChecksum = snapshot.Checksum();

            if (snapshotChecksum != checksumBefore)
            {
                using (Stream @out = new FileStream(TestDir.file("snapshot.zip"), FileMode.Create, FileAccess.Write))
                {
                    snapshot.DumpZip(@out);
                }
                using (Stream @out = new FileStream(TestDir.file("fs.zip"), FileMode.Create, FileAccess.Write))
                {
                    Fs.get().dumpZip(@out);
                }
            }
            assertThat(snapshotChecksum, equalTo(checksumBefore));

            // Recover with unsupported.dbms.id_generator_fast_rebuild_enabled=false
            AssertNumberOfFreeIdsEquals(TestDir.databaseDir(), snapshot, 0);
            GraphDatabaseAPI           newDb             = ( GraphDatabaseAPI )(new TestGraphDatabaseFactory()).setFileSystem(snapshot).newImpermanentDatabaseBuilder(TestDir.databaseDir()).setConfig(GraphDatabaseSettings.rebuild_idgenerators_fast, FALSE).newGraphDatabase();
            IDictionary <IdType, long> highIdsAfterCrash = GetHighIds(newDb);

            assertEquals(highIdsBeforeCrash, highIdsAfterCrash);

            try
            {
                using (Transaction tx = newDb.BeginTx())
                {
                    // Verify that the data we didn't delete is still around
                    int nameCount = 0;
                    int relCount  = 0;
                    foreach (Node node in newDb.AllNodes)
                    {
                        nameCount++;
                        assertThat(node, inTx(newDb, hasProperty("name"), true));
                        relCount += ( int )Iterables.count(node.GetRelationships(Direction.OUTGOING));
                    }

                    assertEquals(16, nameCount);
                    assertEquals(12, relCount);

                    // Verify that the ids of the nodes we deleted are reused
                    IList <long> newIds = new List <long>();
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    newIds.Add(newDb.CreateNode().Id);
                    assertThat(newIds, @is(deletedNodeIds));
                    tx.Success();
                }
            }
            finally
            {
                newDb.Shutdown();
                snapshot.Dispose();
            }
        }