Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testChangeProperty2()
        public virtual void TestChangeProperty2()
        {
            // Create relationship with "test"="test1"
            Node         node1 = GraphDb.createNode();
            Node         node2 = GraphDb.createNode();
            Relationship rel   = node1.CreateRelationshipTo(node2, TEST);

            rel.SetProperty("test", "test1");
            NewTransaction();               // commit

            // Remove "test" and set "test"="test3" instead
            rel.RemoveProperty("test");
            rel.SetProperty("test", "test3");
            assertEquals("test3", rel.GetProperty("test"));
            NewTransaction();               // commit

            // Remove "test" and set "test"="test4" instead
            assertEquals("test3", rel.GetProperty("test"));
            rel.RemoveProperty("test");
            rel.SetProperty("test", "test4");
            NewTransaction();               // commit

            // Should still be "test4"
            assertEquals("test4", rel.GetProperty("test"));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAddProperty()
        public virtual void TestAddProperty()
        {
            string key3 = "key3";

            Node         node1 = GraphDb.getNodeById(_node1Id);
            Node         node2 = GraphDb.getNodeById(_node2Id);
            Relationship rel   = node1.GetSingleRelationship(MyRelTypes.TEST, Direction.BOTH);

            // add new property
            node2.SetProperty(key3, _int1);
            rel.SetProperty(key3, _int2);
            assertTrue(node1.HasProperty(_key1));
            assertTrue(node2.HasProperty(_key1));
            assertTrue(node1.HasProperty(_key2));
            assertTrue(node2.HasProperty(_key2));
            assertTrue(node1.HasProperty(_arrayKey));
            assertTrue(node2.HasProperty(_arrayKey));
            assertTrue(rel.HasProperty(_arrayKey));
            assertTrue(!node1.HasProperty(key3));
            assertTrue(node2.HasProperty(key3));
            assertEquals(_int1, node1.GetProperty(_key1));
            assertEquals(_int2, node2.GetProperty(_key1));
            assertEquals(_string1, node1.GetProperty(_key2));
            assertEquals(_string2, node2.GetProperty(_key2));
            assertEquals(_int1, rel.GetProperty(_key1));
            assertEquals(_string1, rel.GetProperty(_key2));
            assertEquals(_int2, rel.GetProperty(key3));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRelMultiRemoveProperty()
        public virtual void TestRelMultiRemoveProperty()
        {
            Node         node1 = GraphDb.createNode();
            Node         node2 = GraphDb.createNode();
            Relationship rel   = node1.CreateRelationshipTo(node2, MyRelTypes.TEST);

            rel.SetProperty("key0", "0");
            rel.SetProperty("key1", "1");
            rel.SetProperty("key2", "2");
            rel.SetProperty("key3", "3");
            rel.SetProperty("key4", "4");
            NewTransaction();
            rel.RemoveProperty("key3");
            rel.RemoveProperty("key2");
            rel.RemoveProperty("key3");
            NewTransaction();
            assertEquals("0", rel.GetProperty("key0"));
            assertEquals("1", rel.GetProperty("key1"));
            assertEquals("4", rel.GetProperty("key4"));
            assertTrue(!rel.HasProperty("key2"));
            assertTrue(!rel.HasProperty("key3"));
            rel.Delete();
            node1.Delete();
            node2.Delete();
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testCreateRelOnDeletedNode()
        public virtual void TestCreateRelOnDeletedNode()
        {
            Node        node1 = GraphDb.createNode();
            Node        node2 = GraphDb.createNode();
            Transaction tx    = Transaction;

            tx.Success();
            tx.Close();
            tx = GraphDb.beginTx();
            node1.Delete();
            try
            {
                node1.CreateRelationshipTo(node2, MyRelTypes.TEST);
                fail("Create of rel on deleted node should fail fast");
            }
            catch (Exception)
            {               // ok
            }
            try
            {
                tx.Failure();
                tx.Close();
                // fail( "Transaction should be marked rollback" );
            }
            catch (Exception)
            {               // good
            }
            Transaction = GraphDb.beginTx();
            node2.Delete();
            node1.Delete();
        }
Exemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void useTraverserInsideTraverser()
        public virtual void UseTraverserInsideTraverser()
        {
            /*
             * (a)-->(b)-->(c)
             *  |
             * \/
             * (d)-->(e)-->(f)
             *
             */

            CreateGraph("a FIRST d", "a TO b", "b TO c", "d TO e", "e TO f");

            using (Transaction tx = BeginTx())
            {
                TraversalDescription firstTraverser = GraphDb.traversalDescription().relationships(RelationshipType.withName("FIRST")).evaluator(Evaluators.toDepth(1));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Iterable<org.neo4j.graphdb.Path> firstResult = firstTraverser.traverse(getNodeWithName("a"));
                IEnumerable <Path> firstResult = firstTraverser.Traverse(GetNodeWithName("a"));

                IEnumerable <Node> startNodesForNestedTraversal = new IterableWrapperAnonymousInnerClass(this, firstResult);

                TraversalDescription nestedTraversal = GraphDb.traversalDescription().evaluator(Evaluators.atDepth(2));
                ExpectPaths(nestedTraversal.Traverse(startNodesForNestedTraversal), "a,b,c", "d,e,f");
                tx.Success();
            }
        }
Exemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testCircularBug()
        public virtual void TestCircularBug()
        {
            const long timestamp = 3;

            using (Transaction tx = BeginTx())
            {
                GetNodeWithName("2").setProperty("timestamp", 1L);
                GetNodeWithName("3").setProperty("timestamp", 2L);
                tx.Success();
            }

            using (Transaction tx2 = BeginTx())
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.RelationshipType type = org.neo4j.graphdb.RelationshipType.withName("TO");
                RelationshipType   type  = RelationshipType.withName("TO");
                IEnumerator <Node> nodes = GraphDb.traversalDescription().depthFirst().relationships(type, Direction.OUTGOING).evaluator(path =>
                {
                    Relationship rel = path.lastRelationship();
                    bool relIsOfType = rel != null && rel.isType(type);
                    bool prune       = relIsOfType && ( long? )path.endNode().getProperty("timestamp").Value >= timestamp;
                    return(Evaluation.of(relIsOfType, !prune));
                }).traverse(Node("1")).nodes().GetEnumerator();

//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals("2", nodes.next().getProperty("name"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertEquals("3", nodes.next().getProperty("name"));
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                assertFalse(nodes.hasNext());
            }
        }
Exemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNodeAddProperty()
        public virtual void TestNodeAddProperty()
        {
            Node node1 = GraphDb.createNode();
            Node node2 = GraphDb.createNode();

            string key1    = "key1";
            string key2    = "key2";
            string key3    = "key3";
            int?   int1    = 1;
            int?   int2    = 2;
            string string1 = "1";
            string string2 = "2";

            // add property
            node1.SetProperty(key1, int1);
            node2.SetProperty(key1, string1);
            node1.SetProperty(key2, string2);
            node2.SetProperty(key2, int2);
            assertTrue(node1.HasProperty(key1));
            assertTrue(node2.HasProperty(key1));
            assertTrue(node1.HasProperty(key2));
            assertTrue(node2.HasProperty(key2));
            assertTrue(!node1.HasProperty(key3));
            assertTrue(!node2.HasProperty(key3));
            assertEquals(int1, node1.GetProperty(key1));
            assertEquals(string1, node2.GetProperty(key1));
            assertEquals(string2, node1.GetProperty(key2));
            assertEquals(int2, node2.GetProperty(key2));
        }
Exemplo n.º 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void checkDeletesRemoveRecordsWhenProper()
        public virtual void CheckDeletesRemoveRecordsWhenProper()
        {
            Node node = GraphDb.createNode();
            long recordsInUseAtStart = PropertyRecordsInUse();

            int stuffedBooleans = 0;

            for ( ; stuffedBooleans < PropertyType.PayloadSizeLongs; stuffedBooleans++)
            {
                node.SetProperty("boolean" + stuffedBooleans, stuffedBooleans % 2 == 0);
            }
            NewTransaction();

            assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());

            node.SetProperty("theExraOne", true);
            NewTransaction();

            assertEquals(recordsInUseAtStart + 2, PropertyRecordsInUse());

            for (int i = 0; i < stuffedBooleans; i++)
            {
                assertEquals(Convert.ToBoolean(i % 2 == 0), node.RemoveProperty("boolean" + i));
            }
            NewTransaction();

            assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());

            for (int i = 0; i < stuffedBooleans; i++)
            {
                assertFalse(node.HasProperty("boolean" + i));
            }
            assertEquals(true, node.GetProperty("theExraOne"));
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testAdditionHappensInTheMiddleIfItFits()
        public virtual void TestAdditionHappensInTheMiddleIfItFits()
        {
            Node node = GraphDb.createNode();

            long recordsInUseAtStart = PropertyRecordsInUse();

            node.SetProperty("int1", 1);
            node.SetProperty("double1", 1.0);
            node.SetProperty("int2", 2);

            int stuffedShortStrings = 0;

            for ( ; stuffedShortStrings < PropertyType.PayloadSizeLongs; stuffedShortStrings++)
            {
                node.SetProperty("shortString" + stuffedShortStrings, stuffedShortStrings.ToString());
            }
            NewTransaction();

            assertEquals(recordsInUseAtStart + 2, PropertyRecordsInUse());

            node.RemoveProperty("shortString" + 1);
            node.SetProperty("int3", 3);

            NewTransaction();

            assertEquals(recordsInUseAtStart + 2, PropertyRecordsInUse());
        }
Exemplo n.º 10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void setPropertyAndClearCacheBeforeCommit()
        public virtual void SetPropertyAndClearCacheBeforeCommit()
        {
            Node node = GraphDb.createNode();

            node.SetProperty("name", "Test");
            assertEquals("Test", node.GetProperty("name"));
        }
Exemplo n.º 11
0
        /*
         * Creates a PropertyRecord, fills it up, removes something and
         * adds something that should fit.
         */
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void deleteAndAddToFullPropertyRecord()
        public virtual void DeleteAndAddToFullPropertyRecord()
        {
            // Fill it up, each integer is one block
            Node node = GraphDb.createNode();

            for (int i = 0; i < PropertyType.PayloadSizeLongs; i++)
            {
                node.SetProperty("prop" + i, i);
            }

            NewTransaction();

            // Remove all but one and add one
            for (int i = 0; i < PropertyType.PayloadSizeLongs - 1; i++)
            {
                assertEquals(i, node.RemoveProperty("prop" + i));
            }
            node.SetProperty("profit", 5);

            NewTransaction();

            // Verify
            int remainingProperty = PropertyType.PayloadSizeLongs - 1;

            assertEquals(remainingProperty, node.GetProperty("prop" + remainingProperty));
            assertEquals(5, node.GetProperty("profit"));
        }
Exemplo n.º 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void createAndClearCacheBeforeCommit()
        public virtual void CreateAndClearCacheBeforeCommit()
        {
            Node node = GraphDb.createNode();

            node.CreateRelationshipTo(GraphDb.createNode(), TEST);
            assertEquals(1, Iterables.count(node.Relationships));
        }
Exemplo n.º 13
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void getAllRelationships()
        public virtual void getAllRelationships()
        {
            ISet <Relationship> existingRelationships = Iterables.addToCollection(GraphDb.AllRelationships, new HashSet <Relationship>());

            ISet <Relationship> createdRelationships = new HashSet <Relationship>();
            Node node = GraphDb.createNode();

            for (int i = 0; i < 100; i++)
            {
                createdRelationships.Add(node.CreateRelationshipTo(GraphDb.createNode(), TEST));
            }
            NewTransaction();

            ISet <Relationship> allRelationships = new HashSet <Relationship>();

            allRelationships.addAll(existingRelationships);
            allRelationships.addAll(createdRelationships);

            int count = 0;

            foreach (Relationship rel in GraphDb.AllRelationships)
            {
                assertTrue("Unexpected rel " + rel + ", expected one of " + allRelationships, allRelationships.Contains(rel));
                count++;
            }
            assertEquals(allRelationships.Count, count);
        }
Exemplo n.º 14
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testSimple2()
        public virtual void TestSimple2()
        {
            Node node1 = GraphDb.createNode();
            Node node2 = GraphDb.createNode();

            for (int i = 0; i < 3; i++)
            {
                node1.CreateRelationshipTo(node2, TEST);
                node1.CreateRelationshipTo(node2, TEST_TRAVERSAL);
                node1.CreateRelationshipTo(node2, TEST2);
            }
            AllGetRelationshipMethods(node1, Direction.OUTGOING);
            AllGetRelationshipMethods(node2, Direction.INCOMING);
            NewTransaction();
            AllGetRelationshipMethods(node1, Direction.OUTGOING);
            AllGetRelationshipMethods(node2, Direction.INCOMING);
            DeleteFirst((ResourceIterable <Relationship>)node1.GetRelationships(TEST, Direction.OUTGOING));
            DeleteFirst((ResourceIterable <Relationship>)node1.GetRelationships(TEST_TRAVERSAL, Direction.OUTGOING));
            DeleteFirst((ResourceIterable <Relationship>)node1.GetRelationships(TEST2, Direction.OUTGOING));
            node1.CreateRelationshipTo(node2, TEST);
            node1.CreateRelationshipTo(node2, TEST_TRAVERSAL);
            node1.CreateRelationshipTo(node2, TEST2);
            AllGetRelationshipMethods(node1, Direction.OUTGOING);
            AllGetRelationshipMethods(node2, Direction.INCOMING);
            NewTransaction();
            AllGetRelationshipMethods(node1, Direction.OUTGOING);
            AllGetRelationshipMethods(node2, Direction.INCOMING);
            foreach (Relationship rel in node1.Relationships)
            {
                rel.Delete();
            }
            node1.Delete();
            node2.Delete();
        }
Exemplo n.º 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void withLoops()
        public virtual void WithLoops()
        {
            // Just to make sure it doesn't work by accident what with ids aligning with count
            for (int i = 0; i < 10; i++)
            {
                GraphDb.createNode().createRelationshipTo(GraphDb.createNode(), MyRelTypes.TEST);
            }

            Node node = GraphDb.createNode();

            assertEquals(0, node.Degree);
            node.CreateRelationshipTo(node, MyRelTypes.TEST);
            assertEquals(1, node.Degree);
            Node         otherNode = GraphDb.createNode();
            Relationship rel2      = node.CreateRelationshipTo(otherNode, MyRelTypes.TEST2);

            assertEquals(2, node.Degree);
            assertEquals(1, otherNode.Degree);
            NewTransaction();
            assertEquals(2, node.Degree);
            Relationship rel3 = node.CreateRelationshipTo(node, MyRelTypes.TEST_TRAVERSAL);

            assertEquals(3, node.Degree);
            assertEquals(1, otherNode.Degree);
            rel2.Delete();
            assertEquals(2, node.Degree);
            assertEquals(0, otherNode.Degree);
            rel3.Delete();
            assertEquals(1, node.Degree);
        }
Exemplo n.º 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRevertOverflowingChange()
        public virtual void TestRevertOverflowingChange()
        {
            Relationship rel = GraphDb.createNode().createRelationshipTo(GraphDb.createNode(), RelationshipType.withName("INVALIDATES"));

            long recordsInUseAtStart      = PropertyRecordsInUse();
            long valueRecordsInUseAtStart = DynamicArrayRecordsInUse();

            rel.SetProperty("theByte", ( sbyte )-8);
            rel.SetProperty("theDoubleThatGrows", Math.PI);
            rel.SetProperty("theInteger", -444345);

            rel.SetProperty("theDoubleThatGrows", new long[] { 1L << 63, 1L << 63, 1L << 63 });

            rel.SetProperty("theDoubleThatGrows", Math.E);

            // When
            NewTransaction();

            // Then

            /*
             * The following line should pass if we have packing on property block
             * size shrinking.
             */
            // assertEquals( recordsInUseAtStart + 1, propertyRecordsInUse() );
            assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());
            assertEquals(valueRecordsInUseAtStart, DynamicArrayRecordsInUse());

            assertEquals(( sbyte )-8, rel.GetProperty("theByte"));
            assertEquals(-444345, rel.GetProperty("theInteger"));
            assertEquals(Math.E, rel.GetProperty("theDoubleThatGrows"));
        }
Exemplo n.º 17
0
 private void AssertPropertyEqual(PropertyContainer primitive, string key, string value)
 {
     using (Transaction tx = GraphDb.beginTx())
     {
         assertEquals(value, primitive.GetProperty(key));
     }
 }
Exemplo n.º 18
0
        private void TestYoyoArrayBase(bool withNewTx)
        {
            Relationship rel = GraphDb.createNode().createRelationshipTo(GraphDb.createNode(), RelationshipType.withName("LOCKS"));

            long recordsInUseAtStart      = PropertyRecordsInUse();
            long valueRecordsInUseAtStart = DynamicArrayRecordsInUse();

            IList <long> theYoyoData = new List <long>();

            for (int i = 0; i < PropertyType.PayloadSizeLongs - 1; i++)
            {
                theYoyoData.Add(1L << 63);
                long?[] value = theYoyoData.ToArray();
                rel.SetProperty("yoyo", value);
                if (withNewTx)
                {
                    NewTransaction();
                    assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());
                    assertEquals(valueRecordsInUseAtStart, DynamicArrayRecordsInUse());
                }
            }

            theYoyoData.Add(1L << 63);
            long?[] value = theYoyoData.ToArray();
            rel.SetProperty("yoyo", value);

            NewTransaction();
            assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());
            assertEquals(valueRecordsInUseAtStart + 1, DynamicArrayRecordsInUse());
            rel.SetProperty("filler", new long[] { 1L << 63, 1L << 63, 1L << 63 });
            NewTransaction();
            assertEquals(recordsInUseAtStart + 2, PropertyRecordsInUse());
        }
Exemplo n.º 19
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void sortFriendsByName()
        public virtual void SortFriendsByName()
        {
            /*
             *      (Abraham)
             *          |
             *         (me)--(George)--(Dan)
             *          |        |
             *       (Zack)---(Andreas)
             *                   |
             *              (Nicholas)
             */

            string me       = "me";
            string abraham  = "Abraham";
            string george   = "George";
            string dan      = "Dan";
            string zack     = "Zack";
            string andreas  = "Andreas";
            string nicholas = "Nicholas";
            string knows    = "KNOWS";

            CreateGraph(Triplet(me, knows, abraham), Triplet(me, knows, george), Triplet(george, knows, dan), Triplet(me, knows, zack), Triplet(zack, knows, andreas), Triplet(george, knows, andreas), Triplet(andreas, knows, nicholas));

            using (Transaction tx = BeginTx())
            {
                IList <Node> nodes = AsNodes(abraham, george, dan, zack, andreas, nicholas);
                assertEquals(nodes, Iterables.asCollection(GraphDb.traversalDescription().evaluator(excludeStartPosition()).sort(endNodeProperty("name")).traverse(GetNodeWithName(me)).nodes()));
                tx.Success();
            }
        }
Exemplo n.º 20
0
        private void TestStringYoYoBase(bool withNewTx)
        {
            Node node = GraphDb.createNode();

            long recordsInUseAtStart      = PropertyRecordsInUse();
            long valueRecordsInUseAtStart = DynamicStringRecordsInUse();

            string data    = "0";
            int    counter = 1;

            while (DynamicStringRecordsInUse() == valueRecordsInUseAtStart)
            {
                data += counter++;
                node.SetProperty("yoyo", data);
                if (withNewTx)
                {
                    NewTransaction();
                    assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());
                }
            }

            data = data.Substring(0, data.Length - 2);
            node.SetProperty("yoyo", data);

            NewTransaction();

            assertEquals(valueRecordsInUseAtStart, DynamicStringRecordsInUse());
            assertEquals(recordsInUseAtStart + 1, PropertyRecordsInUse());

            node.SetProperty("fillerBoolean", true);

            NewTransaction();
            assertEquals(recordsInUseAtStart + 2, PropertyRecordsInUse());
        }
Exemplo n.º 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testNodeChangeProperty2()
        public virtual void TestNodeChangeProperty2()
        {
            string key1    = "key1";
            int?   int1    = 1;
            int?   int2    = 2;
            string string1 = "1";
            string string2 = "2";
            bool?  bool1   = true;
            bool?  bool2   = false;
            Node   node1   = GraphDb.createNode();

            node1.SetProperty(key1, int1);
            node1.SetProperty(key1, int2);
            assertEquals(int2, node1.GetProperty(key1));
            node1.RemoveProperty(key1);
            node1.SetProperty(key1, string1);
            node1.SetProperty(key1, string2);
            assertEquals(string2, node1.GetProperty(key1));
            node1.RemoveProperty(key1);
            node1.SetProperty(key1, bool1);
            node1.SetProperty(key1, bool2);
            assertEquals(bool2, node1.GetProperty(key1));
            node1.RemoveProperty(key1);
            node1.Delete();
        }
Exemplo n.º 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void simpleAddDoubles()
        public virtual void SimpleAddDoubles()
        {
            long inUseBefore = PropertyRecordsInUse();
            Node node        = GraphDb.createNode();

            for (int i = 0; i < PropertyType.PayloadSizeLongs / 2; i++)
            {
                node.SetProperty("prop" + i, i * -1.0);
                assertEquals(i * -1.0, node.GetProperty("prop" + i));
            }

            NewTransaction();
            assertEquals(inUseBefore + 1, PropertyRecordsInUse());

            for (int i = 0; i < PropertyType.PayloadSizeLongs / 2; i++)
            {
                assertEquals(i * -1.0, node.GetProperty("prop" + i));
            }

            for (int i = 0; i < PropertyType.PayloadSizeLongs / 2; i++)
            {
                assertEquals(i * -1.0, node.RemoveProperty("prop" + i));
                assertFalse(node.HasProperty("prop" + i));
            }
            Commit();
            assertEquals(inUseBefore, PropertyRecordsInUse());
        }
Exemplo n.º 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testDeleteReferenceNodeOrLastNodeIsOk()
        public virtual void TestDeleteReferenceNodeOrLastNodeIsOk()
        {
            Transaction tx = Transaction;

            for (int i = 0; i < 10; i++)
            {
                GraphDb.createNode();
            }
            // long numNodesPre = getNodeManager().getNumberOfIdsInUse( Node.class
            // );
            // empty the DB instance
            foreach (Node node in GraphDb.AllNodes)
            {
                foreach (Relationship rel in node.Relationships)
                {
                    rel.Delete();
                }
                node.Delete();
            }
            tx.Success();
            tx.Close();
            tx = GraphDb.beginTx();
            assertFalse(GraphDb.AllNodes.GetEnumerator().hasNext());
            // TODO: this should be valid, fails right now!
            // assertEquals( 0, numNodesPost );
            tx.Success();
            tx.Close();
        }
Exemplo n.º 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void releaseReleaseManually() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ReleaseReleaseManually()
        {
            string key  = "name";
            Node   node = GraphDb.createNode();

            Tx.success();
            Transaction current  = Tx.begin();
            Lock        nodeLock = current.AcquireWriteLock(node);

            _worker.beginTx();
            try
            {
                _worker.setProperty(node, key, "ksjd");
                fail("Shouldn't be able to grab it");
            }
            catch (Exception)
            {
            }
            nodeLock.Release();
            _worker.setProperty(node, key, "yo");

            try
            {
                _worker.finishTx();
            }
            catch (ExecutionException)
            {
                // Ok, interrupting the thread while it's waiting for a lock will lead to tx failure.
            }
        }
Exemplo n.º 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void myFriendsAsWellAsYourFriends()
        public virtual void MyFriendsAsWellAsYourFriends()
        {
            /*
             * Hey, this looks like a futuristic gun or something
             *
             *  (f8)     _----(f1)--(f5)
             *   |      /      /
             * (f7)--(you)--(me)--(f2)--(f6)
             *         |   /   \
             *         (f4)    (f3)
             */

            CreateGraph("you KNOW me", "you KNOW f1", "you KNOW f4", "me KNOW f1", "me KNOW f4", "me KNOW f2", "me KNOW f3", "f1 KNOW f5", "f2 KNOW f6", "you KNOW f7", "f7 KNOW f8");

            using (Transaction tx = BeginTx())
            {
                RelationshipType knowRelType = withName("KNOW");
                Node             you         = GetNodeWithName("you");
                Node             me          = GetNodeWithName("me");

                string[]             levelOneFriends   = new string[] { "f1", "f2", "f3", "f4", "f7" };
                TraversalDescription levelOneTraversal = GraphDb.traversalDescription().relationships(knowRelType).evaluator(atDepth(1));
                ExpectNodes(levelOneTraversal.DepthFirst().traverse(you, me), levelOneFriends);
                ExpectNodes(levelOneTraversal.BreadthFirst().traverse(you, me), levelOneFriends);

                string[]             levelTwoFriends   = new string[] { "f5", "f6", "f8" };
                TraversalDescription levelTwoTraversal = GraphDb.traversalDescription().relationships(knowRelType).evaluator(atDepth(2));
                ExpectNodes(levelTwoTraversal.DepthFirst().traverse(you, me), levelTwoFriends);
                ExpectNodes(levelTwoTraversal.BreadthFirst().traverse(you, me), levelTwoFriends);
            }
        }
Exemplo n.º 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void convertNodeToDense()
        public virtual void ConvertNodeToDense()
        {
            Node node = GraphDb.createNode();
            Dictionary <MyRelTypes, ISet <Relationship> > rels = new Dictionary <MyRelTypes, ISet <Relationship> >(typeof(MyRelTypes));

            foreach (MyRelTypes type in Enum.GetValues(typeof(MyRelTypes)))
            {
                rels[type] = new HashSet <Relationship>();
            }
            int expectedRelCount = 0;

            for (int i = 0; i < 6; i++, expectedRelCount++)
            {
                MyRelTypes   type = Enum.GetValues(typeof(MyRelTypes))[i % Enum.GetValues(typeof(MyRelTypes)).length];
                Relationship rel  = node.CreateRelationshipTo(GraphDb.createNode(), type);
                rels[type].Add(rel);
            }
            NewTransaction();
            for (int i = 0; i < 1000; i++, expectedRelCount++)
            {
                node.CreateRelationshipTo(GraphDb.createNode(), MyRelTypes.TEST);
            }

            assertEquals(expectedRelCount, node.Degree);
            assertEquals(expectedRelCount, node.GetDegree(Direction.BOTH));
            assertEquals(expectedRelCount, node.GetDegree(Direction.OUTGOING));
            assertEquals(0, node.GetDegree(Direction.INCOMING));
            assertEquals(rels[MyRelTypes.TEST2], Iterables.asSet(node.GetRelationships(MyRelTypes.TEST2)));
            assertEquals(Join(rels[MyRelTypes.TEST_TRAVERSAL], rels[MyRelTypes.TEST2]), Iterables.asSet(node.GetRelationships(MyRelTypes.TEST_TRAVERSAL, MyRelTypes.TEST2)));
        }
Exemplo n.º 27
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testGetDirectedRelationship()
        public virtual void TestGetDirectedRelationship()
        {
            Node         node1 = GraphDb.getNodeById(_node1Id);
            Relationship rel   = node1.GetSingleRelationship(MyRelTypes.TEST, Direction.OUTGOING);

            assertEquals(_int1, rel.GetProperty(_key1));
        }
Exemplo n.º 28
0
        private void TestGetRelationshipTypes(Node node, ISet <string> expectedTypes)
        {
            AssertExpectedRelationshipTypes(expectedTypes, node, false);
            node.CreateRelationshipTo(GraphDb.createNode(), RelType.Type1);
            expectedTypes.Add(RelType.Type1.name());
            AssertExpectedRelationshipTypes(expectedTypes, node, false);
            node.CreateRelationshipTo(GraphDb.createNode(), RelType.Type1);
            AssertExpectedRelationshipTypes(expectedTypes, node, true);

            Relationship rel = node.CreateRelationshipTo(GraphDb.createNode(), RelType.Type2);

            expectedTypes.Add(RelType.Type2.name());
            AssertExpectedRelationshipTypes(expectedTypes, node, false);
            rel.Delete();
            expectedTypes.remove(RelType.Type2.name());
            AssertExpectedRelationshipTypes(expectedTypes, node, true);

            node.CreateRelationshipTo(GraphDb.createNode(), RelType.Type2);
            node.CreateRelationshipTo(GraphDb.createNode(), RelType.Type2);
            expectedTypes.Add(RelType.Type2.name());
            node.CreateRelationshipTo(GraphDb.createNode(), MyRelTypes.TEST);
            expectedTypes.Add(MyRelTypes.TEST.name());
            AssertExpectedRelationshipTypes(expectedTypes, node, true);

            foreach (Relationship r in node.GetRelationships(RelType.Type1))
            {
                AssertExpectedRelationshipTypes(expectedTypes, node, false);
                r.Delete();
            }
            expectedTypes.remove(RelType.Type1.name());
            AssertExpectedRelationshipTypes(expectedTypes, node, true);
        }
Exemplo n.º 29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void createTestingGraph()
        public virtual void CreateTestingGraph()
        {
            Node         node1 = GraphDb.createNode();
            Node         node2 = GraphDb.createNode();
            Relationship rel   = node1.CreateRelationshipTo(node2, MyRelTypes.TEST);

            _node1Id = node1.Id;
            _node2Id = node2.Id;
            node1.SetProperty(_key1, _int1);
            node1.SetProperty(_key2, _string1);
            node2.SetProperty(_key1, _int2);
            node2.SetProperty(_key2, _string2);
            rel.SetProperty(_key1, _int1);
            rel.SetProperty(_key2, _string1);
            node1.SetProperty(_arrayKey, _array);
            node2.SetProperty(_arrayKey, _array);
            rel.SetProperty(_arrayKey, _array);
            Transaction tx = Transaction;

            tx.Success();
            tx.Close();
            tx = GraphDb.beginTx();
            assertEquals(1, node1.GetProperty(_key1));
            Transaction = tx;
        }
Exemplo n.º 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testRelationshipChangeProperty2()
        public virtual void TestRelationshipChangeProperty2()
        {
            int?   int1    = 1;
            int?   int2    = 2;
            string string1 = "1";
            string string2 = "2";

            Node         node1 = GraphDb.createNode();
            Node         node2 = GraphDb.createNode();
            Relationship rel1  = node1.CreateRelationshipTo(node2, TEST);

            rel1.SetProperty(_key1, int1);
            rel1.SetProperty(_key1, int2);
            assertEquals(int2, rel1.GetProperty(_key1));
            rel1.RemoveProperty(_key1);
            rel1.SetProperty(_key1, string1);
            rel1.SetProperty(_key1, string2);
            assertEquals(string2, rel1.GetProperty(_key1));
            rel1.RemoveProperty(_key1);
            rel1.SetProperty(_key1, true);
            rel1.SetProperty(_key1, false);
            assertEquals(false, rel1.GetProperty(_key1));
            rel1.RemoveProperty(_key1);

            rel1.Delete();
            node2.Delete();
            node1.Delete();
        }