예제 #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void TerminateLongRunningRestTransactionalEndpointWithCustomTimeoutQuery()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  OpenEnterpriseNeoServer neoServer = StartNeoServer( ( GraphDatabaseFacade ) database );
			  long customTimeout = TimeUnit.SECONDS.toMillis( 10 );
			  HTTP.Response beginResponse = HTTP.withHeaders( HttpHeaderUtils.MAX_EXECUTION_TIME_HEADER, customTimeout.ToString() ).POST(TransactionUri(neoServer), quotedJson("{ 'statements': [ { 'statement': 'CREATE (n)' } ] }"));
			  assertEquals( "Response should be successful.", 201, beginResponse.Status() );

			  string transactionEndPoint = beginResponse.Location();
			  _fakeClock.forward( 3, TimeUnit.SECONDS );

			  HTTP.Response response = HTTP.POST( transactionEndPoint, quotedJson( "{ 'statements': [ { 'statement': 'CREATE (n)' } ] }" ) );
			  assertEquals( "Response should be successful.", 200, response.Status() );

			  _fakeClock.forward( 11, TimeUnit.SECONDS );
			  timeoutMonitor.Run();

			  response = HTTP.POST( transactionEndPoint, quotedJson( "{ 'statements': [ { 'statement': 'CREATE (n)' } ] }" ) );
			  assertEquals( "Response should be successful.", 200, response.Status() );

			  HTTP.Response commitResponse = HTTP.POST( transactionEndPoint + "/commit" );
			  assertEquals( "Transaction should be already closed and not found.", 404, commitResponse.Status() );

			  assertEquals( "Transaction should be forcefully closed.", TransactionNotFound.code().serialize(), commitResponse.Get("errors").findValue("code").asText() );
			  AssertDatabaseDoesNotHaveNodes( database );
		 }
예제 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateLongRunningDriverQuery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void TerminateLongRunningDriverQuery()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  OpenEnterpriseNeoServer neoServer = StartNeoServer( ( GraphDatabaseFacade ) database );

			  Org.Neo4j.driver.v1.Config driverConfig = DriverConfig;

			  using ( Driver driver = GraphDatabase.driver( "bolt://localhost:" + _boltPortDatabaseWithTimeout, driverConfig ), Session session = driver.session() )
			  {
					Org.Neo4j.driver.v1.Transaction transaction = session.beginTransaction();
					transaction.run( "create (n)" ).consume();
					transaction.success();
					_fakeClock.forward( 3, TimeUnit.SECONDS );
					timeoutMonitor.Run();
					try
					{
						 transaction.run( "create (n)" ).consume();
						 fail( "Transaction should be already terminated by execution guard." );
					}
					catch ( Exception )
					{
						 // ignored
					}
			  }
			  AssertDatabaseDoesNotHaveNodes( database );
		 }
예제 #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateLongRunningQueryWithCustomTimeoutWithoutConfiguredDefault()
		 public virtual void TerminateLongRunningQueryWithCustomTimeoutWithoutConfiguredDefault()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithoutTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  using ( Transaction transaction = database.BeginTx( 5, TimeUnit.SECONDS ) )
			  {
					_fakeClock.forward( 4, TimeUnit.SECONDS );
					timeoutMonitor.Run();
					database.Execute( "create (n)" );
					transaction.Failure();
			  }

			  try
			  {
					  using ( Transaction transaction = database.BeginTx( 6, TimeUnit.SECONDS ) )
					  {
						_fakeClock.forward( 7, TimeUnit.SECONDS );
						timeoutMonitor.Run();
						transaction.Success();
						database.Execute( "create (n)" );
						fail( "Transaction should be already terminated." );
					  }
			  }
			  catch ( TransactionTerminatedException e )
			  {
					assertThat( e.Message, startsWith( "The transaction has been terminated." ) );
			  }

			  AssertDatabaseDoesNotHaveNodes( database );
		 }
예제 #4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void changeTimeoutAtRuntime()
		 public virtual void ChangeTimeoutAtRuntime()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  try
			  {
					  using ( Transaction transaction = database.BeginTx() )
					  {
						_fakeClock.forward( 3, TimeUnit.SECONDS );
						timeoutMonitor.Run();
						transaction.Success();
						database.Execute( "create (n)" );
						fail( "Transaction should be already terminated." );
					  }
			  }
			  catch ( TransactionTerminatedException e )
			  {
					assertThat( e.Message, startsWith( "The transaction has been terminated." ) );
			  }

			  AssertDatabaseDoesNotHaveNodes( database );

			  // Increase timeout
			  using ( Transaction transaction = database.BeginTx() )
			  {
					database.Execute( "CALL dbms.setConfigValue('" + transaction_timeout.name() + "', '5s')" );
					transaction.Success();
			  }

			  using ( Transaction transaction = database.BeginTx() )
			  {
					_fakeClock.forward( 3, TimeUnit.SECONDS );
					timeoutMonitor.Run();
					transaction.Success();
					database.Execute( "create (n)" );
			  }

			  // Assert node successfully created
			  using ( Transaction ignored = database.BeginTx() )
			  {
					assertEquals( 1, database.AllNodes.Count() );
			  }

			  // Reset timeout and cleanup
			  using ( Transaction transaction = database.BeginTx() )
			  {
					database.Execute( "CALL dbms.setConfigValue('" + transaction_timeout.name() + "', '" + DEFAULT_TIMEOUT + "')" );
					using ( Stream<Node> stream = database.AllNodes.stream() )
					{
						 stream.findFirst().map(node =>
						 {
						  node.delete();
						  return node;
						 });
					}
					transaction.Success();
			  }
		 }
예제 #5
0
			  internal virtual void TickAndCheck()
			  {
					KernelTransactionMonitor timeoutMonitor = MonitorSupplier.get();
					if ( timeoutMonitor != null )
					{
						 _fakeClock.forward( 1, TimeUnit.SECONDS );
						 timeoutMonitor.Run();
					}
			  }
예제 #6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateLongRunningTransactionWithPeriodicCommit() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void TerminateLongRunningTransactionWithPeriodicCommit()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  _monitorSupplier.TransactionTimeoutMonitor = timeoutMonitor;
			  try
			  {
					URL url = PrepareTestImportFile( 8 );
					database.Execute( "USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();" );
					fail( "Transaction should be already terminated." );
			  }
			  catch ( TransactionTerminatedException )
			  {
			  }
			  AssertDatabaseDoesNotHaveNodes( database );
		 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void skipTransactionWithoutTimeout()
        internal virtual void SkipTransactionWithoutTimeout()
        {
            HashSet <KernelTransactionHandle>     transactions = new HashSet <KernelTransactionHandle>();
            KernelTransactionImplementation       tx1          = PrepareTxMock(7, 3, 0);
            KernelTransactionImplementation       tx2          = PrepareTxMock(8, 4, 0);
            KernelTransactionImplementationHandle handle1      = new KernelTransactionImplementationHandle(tx1, _fakeClock);
            KernelTransactionImplementationHandle handle2      = new KernelTransactionImplementationHandle(tx2, _fakeClock);

            transactions.Add(handle1);
            transactions.Add(handle2);

            when(_kernelTransactions.activeTransactions()).thenReturn(transactions);

            KernelTransactionMonitor transactionMonitor = BuildTransactionMonitor();

            _fakeClock.forward(300, TimeUnit.MILLISECONDS);
            transactionMonitor.Run();

            verify(tx1, never()).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            verify(tx2, never()).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            _logProvider.rawMessageMatcher().assertNotContains("timeout");
        }
예제 #8
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 );
		 }
예제 #9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void terminateLongRunningDriverPeriodicCommitQuery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
		 public virtual void TerminateLongRunningDriverPeriodicCommitQuery()
		 {
			  GraphDatabaseAPI database = StartDatabaseWithTimeout();
			  KernelTransactionMonitor timeoutMonitor = database.DependencyResolver.resolveDependency( typeof( KernelTransactionMonitor ) );
			  _monitorSupplier.TransactionTimeoutMonitor = timeoutMonitor;
			  OpenEnterpriseNeoServer neoServer = StartNeoServer( ( GraphDatabaseFacade ) database );

			  Org.Neo4j.driver.v1.Config driverConfig = DriverConfig;

			  try
			  {
					  using ( Driver driver = GraphDatabase.driver( "bolt://localhost:" + _boltPortDatabaseWithTimeout, driverConfig ), Session session = driver.session() )
					  {
						URL url = PrepareTestImportFile( 8 );
						session.run( "USING PERIODIC COMMIT 5 LOAD CSV FROM '" + url + "' AS line CREATE ();" ).consume();
						fail( "Transaction should be already terminated by execution guard." );
					  }
			  }
			  catch ( Exception )
			  {
					//
			  }
			  AssertDatabaseDoesNotHaveNodes( database );
		 }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void terminateExpiredTransactions()
        internal virtual void TerminateExpiredTransactions()
        {
            HashSet <KernelTransactionHandle>     transactions = new HashSet <KernelTransactionHandle>();
            KernelTransactionImplementation       tx1          = PrepareTxMock(3, 1, 3);
            KernelTransactionImplementation       tx2          = PrepareTxMock(4, 1, 8);
            KernelTransactionImplementationHandle handle1      = new KernelTransactionImplementationHandle(tx1, _fakeClock);
            KernelTransactionImplementationHandle handle2      = new KernelTransactionImplementationHandle(tx2, _fakeClock);

            transactions.Add(handle1);
            transactions.Add(handle2);

            when(_kernelTransactions.activeTransactions()).thenReturn(transactions);

            KernelTransactionMonitor transactionMonitor = BuildTransactionMonitor();

            _fakeClock.forward(3, TimeUnit.MILLISECONDS);
            transactionMonitor.Run();

            verify(tx1, never()).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            verify(tx2, never()).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            _logProvider.rawMessageMatcher().assertNotContains("timeout");

            _fakeClock.forward(2, TimeUnit.MILLISECONDS);
            transactionMonitor.Run();

            verify(tx1).markForTermination(EXPECTED_REUSE_COUNT, Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            verify(tx2, never()).markForTermination(Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            _logProvider.rawMessageMatcher().assertContains("timeout");

            _logProvider.clear();
            _fakeClock.forward(10, TimeUnit.MILLISECONDS);
            transactionMonitor.Run();

            verify(tx2).markForTermination(EXPECTED_REUSE_COUNT, Org.Neo4j.Kernel.Api.Exceptions.Status_Transaction.TransactionTimedOut);
            _logProvider.rawMessageMatcher().assertContains("timeout");
        }