Example #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void validateExplicitIndexedRelationshipProperties()
        internal virtual void ValidateExplicitIndexedRelationshipProperties()
        {
            setUp();
            Label            label        = Label.label("explicitIndexedRelationshipPropertiesTestLabel");
            string           propertyName = "explicitIndexedRelationshipProperties";
            string           explicitIndexedRelationshipIndex = "explicitIndexedRelationshipIndex";
            RelationshipType indexType = RelationshipType.withName("explicitIndexType");

            using (Transaction transaction = _database.beginTx())
            {
                Node         source       = _database.createNode(label);
                Node         destination  = _database.createNode(label);
                Relationship relationship = source.CreateRelationshipTo(destination, indexType);
                _database.index().forRelationships(explicitIndexedRelationshipIndex).add(relationship, propertyName, "shortString");
                transaction.Success();
            }

            System.ArgumentException argumentException = assertThrows(typeof(System.ArgumentException), () =>
            {
                using (Transaction transaction = _database.beginTx())
                {
                    Node source               = _database.createNode(label);
                    Node destination          = _database.createNode(label);
                    Relationship relationship = source.createRelationshipTo(destination, indexType);
                    string longValue          = StringUtils.repeat("a", IndexWriter.MAX_TERM_LENGTH + 1);
                    _database.index().forRelationships(explicitIndexedRelationshipIndex).add(relationship, propertyName, longValue);
                    transaction.Success();
                }
            });
            assertEquals("Property value size is too large for index. Please see index documentation for limitations.", argumentException.Message);
        }
Example #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldWriteOutThePropertyRecordBeforeReferencingItFromARelationshipRecord() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldWriteOutThePropertyRecordBeforeReferencingItFromARelationshipRecord()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long node1Id;
            long node1Id;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long node2Id;
            long node2Id;

            using (Transaction tx = Db.beginTx())
            {
                Node node1 = Db.createNode();
                node1Id = node1.Id;

                Node node2 = Db.createNode();
                node2Id = node2.Id;

                tx.Success();
            }

            Race race = new Race();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long[] latestRelationshipId = new long[1];
            long[]     latestRelationshipId = new long[1];
            AtomicLong writes  = new AtomicLong();
            AtomicLong reads   = new AtomicLong();
            long       endTime = currentTimeMillis() + SECONDS.toMillis(2);

            race.WithEndCondition(() => (writes.get() > 100 && reads.get() > 10_000) || currentTimeMillis() > endTime);
            race.AddContestant(() =>
            {
                using (Transaction tx = Db.beginTx())
                {
                    Node node1 = Db.GraphDatabaseAPI.getNodeById(node1Id);
                    Node node2 = Db.GraphDatabaseAPI.getNodeById(node2Id);

                    Relationship rel        = node1.createRelationshipTo(node2, _friend);
                    latestRelationshipId[0] = rel.Id;
                    rel.setProperty("largeProperty", LONG_STRING_VALUE);

                    tx.Success();
                }
                writes.incrementAndGet();
            });
            race.AddContestant(() =>
            {
                try
                {
                    using (Transaction tx = Db.GraphDatabaseAPI.beginTx())
                    {
                        Relationship rel = Db.GraphDatabaseAPI.getRelationshipById(latestRelationshipId[0]);

                        foreach (string propertyKey in rel.PropertyKeys)
                        {
                            rel.getProperty(propertyKey);
                        }
                        tx.Success();
                    }
                }
                catch (NotFoundException e)
                {
                    if (Exceptions.contains(e, typeof(InvalidRecordException)))
                    {
                        throw e;
                    }
                }
                reads.incrementAndGet();
            });
            race.Go();
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotDeadlockOrCrashFromInconsistency() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotDeadlockOrCrashFromInconsistency()
        {
            // GIVEN (A) -[R]-> (B)
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node a;
            Node a;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.Node b;
            Node b;

            using (Transaction tx = Db.beginTx())
            {
                (a = Db.createNode()).createRelationshipTo(b = Db.createNode(), MyRelTypes.TEST);
                tx.Success();
            }

            // WHEN
            Race race = new Race();

            // a bunch of deleters
            for (int i = 0; i < 30; i++)
            {
                race.AddContestant(() =>
                {
                    for (int j = 0; j < 10; j++)
                    {
                        using (Transaction tx = Db.beginTx())
                        {
                            Node node = Random.nextBoolean() ? a : b;
                            foreach (Relationship relationship in node.Relationships)
                            {
                                try
                                {
                                    relationship.delete();
                                }
                                catch (NotFoundException e)
                                {
                                    // This is OK and expected since there are multiple threads deleting
                                    assertTrue(e.Message.contains("already deleted"));
                                }
                            }
                            tx.Success();
                        }
                    }
                });
            }

            // a bunch of creators
            for (int i = 0; i < 30; i++)
            {
                race.AddContestant(() =>
                {
                    for (int j = 0; j < 10; j++)
                    {
                        using (Transaction tx = Db.beginTx())
                        {
                            bool order = Random.nextBoolean();
                            Node start = order ? a : b;
                            Node end   = order ? b : a;
                            start.createRelationshipTo(end, MyRelTypes.Test);
                            tx.Success();
                        }
                    }
                });
            }

            // THEN there should be no thread throwing exception, especially DeadlockDetectedException
            race.Go();
        }