Ejemplo n.º 1
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 );
		 }
Ejemplo n.º 2
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();
			  }
		 }
Ejemplo n.º 3
0
		 private void AssertDatabaseDoesNotHaveNodes( GraphDatabaseAPI database )
		 {
			  using ( Transaction ignored = database.BeginTx() )
			  {
					assertEquals( 0, database.AllNodes.Count() );
			  }
		 }
Ejemplo n.º 4
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();
     }
 }
Ejemplo n.º 5
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();
     }
 }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void fulltextIndexesMustBeUpdatedByIncrementalBackup()
        public virtual void FulltextIndexesMustBeUpdatedByIncrementalBackup()
        {
            InitializeTestData();
            File backup = _dir.databaseDir("backup");

            OnlineBackup.from("127.0.0.1", _backupPort).backup(backup);

            long nodeId3;
            long nodeId4;
            long relId2;

            using (Transaction tx = _db.beginTx())
            {
                Node node3 = _db.createNode(_label);
                node3.SetProperty(PROP, "Additional data.");
                Node node4 = _db.createNode(_label);
                node4.SetProperty(PROP, "Even more additional data.");
                Relationship rel = node3.CreateRelationshipTo(node4, _rel);
                rel.SetProperty(PROP, "Knows of");
                nodeId3 = node3.Id;
                nodeId4 = node4.Id;
                relId2  = rel.Id;
                tx.Success();
            }
            VerifyData(_db);

            OnlineBackup.from("127.0.0.1", _backupPort).backup(backup);
            _db.shutdown();

            GraphDatabaseAPI backupDb = StartBackupDatabase(backup);

            VerifyData(backupDb);

            using (Transaction tx = backupDb.BeginTx())
            {
                using (Result nodes = backupDb.Execute(format(QUERY_NODES, NODE_INDEX, "additional")))
                {
                    IList <long> nodeIds = nodes.Select(m => (( Node )m.get(NODE)).Id).ToList();
                    assertThat(nodeIds, containsInAnyOrder(nodeId3, nodeId4));
                }
                using (Result relationships = backupDb.Execute(format(QUERY_RELS, REL_INDEX, "knows")))
                {
                    IList <long> relIds = relationships.Select(m => (( Relationship )m.get(RELATIONSHIP)).Id).ToList();
                    assertThat(relIds, containsInAnyOrder(relId2));
                }
                tx.Success();
            }
        }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void assertIndexProvider(org.neo4j.graphdb.GraphDatabaseService db, String expectedProviderIdentifier) throws org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException
        private void AssertIndexProvider(GraphDatabaseService db, string expectedProviderIdentifier)
        {
            GraphDatabaseAPI graphDatabaseAPI = ( GraphDatabaseAPI )db;

            using (Transaction tx = graphDatabaseAPI.BeginTx())
            {
                KernelTransaction ktx       = graphDatabaseAPI.DependencyResolver.resolveDependency(typeof(ThreadToStatementContextBridge)).getKernelTransactionBoundToThisThread(true);
                TokenRead         tokenRead = ktx.TokenRead();
                int            labelId      = tokenRead.NodeLabel(LABEL.name());
                int            propertyId   = tokenRead.PropertyKey(KEY);
                IndexReference index        = ktx.SchemaRead().index(labelId, propertyId);

                assertEquals("expected IndexProvider.Descriptor", expectedProviderIdentifier, (new IndexProviderDescriptor(index.ProviderKey(), index.ProviderVersion())).name());
                tx.Success();
            }
        }
Ejemplo n.º 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 );
		 }
Ejemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public org.neo4j.server.rest.repr.Representation invoke(org.neo4j.kernel.internal.GraphDatabaseAPI graphDb, Object source, ParameterList params) throws BadPluginInvocationException, PluginInvocationFailureException, org.neo4j.server.rest.repr.BadInputException
        public override Representation Invoke(GraphDatabaseAPI graphDb, object source, ParameterList @params)
        {
            object[] arguments = new object[_extractors.Length];
            using (Transaction tx = graphDb.BeginTx())
            {
                for (int i = 0; i < arguments.Length; i++)
                {
                    arguments[i] = _extractors[i].extract(graphDb, source, @params);
                }
            }
            try
            {
                object returned = _method.invoke(_plugin, arguments);

                if (returned == null)
                {
                    return(Representation.emptyRepresentation());
                }
                return(_result.convert(returned));
            }
            catch (InvocationTargetException exc)
            {
                Exception targetExc = exc.TargetException;
                foreach (Type excType in _method.ExceptionTypes)
                {
                    if (excType.IsInstanceOfType(targetExc))
                    {
                        throw new BadPluginInvocationException(targetExc);
                    }
                }
                throw new PluginInvocationFailureException(targetExc);
            }
            catch (Exception e) when(e is System.ArgumentException || e is IllegalAccessException)
            {
                throw new PluginInvocationFailureException(e);
            }
        }
Ejemplo n.º 10
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();
            }
        }