Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldUseConcurrentlyCreatedNode()
        internal virtual void ShouldUseConcurrentlyCreatedNode()
        {
            // given
            GraphDatabaseService graphdb = mock(typeof(GraphDatabaseService));
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") Index<org.neo4j.graphdb.Node> index = mock(Index.class);
            Index <Node> index = mock(typeof(Index));
            Transaction  tx    = mock(typeof(Transaction));

            when(graphdb.BeginTx()).thenReturn(tx);
            when(index.GraphDatabase).thenReturn(graphdb);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") IndexHits<org.neo4j.graphdb.Node> getHits = mock(IndexHits.class);
            IndexHits <Node> getHits = mock(typeof(IndexHits));

            when(index.get("key1", "value1")).thenReturn(getHits);
            Node createdNode = mock(typeof(Node));

            when(graphdb.CreateNode()).thenReturn(createdNode);
            Node concurrentNode = mock(typeof(Node));

            when(index.PutIfAbsent(createdNode, "key1", "value1")).thenReturn(concurrentNode);
            UniqueFactory.UniqueNodeFactory unique = new UniqueNodeFactoryAnonymousInnerClass(this, index);

            // when
            UniqueEntity <Node> node = unique.GetOrCreateWithOutcome("key1", "value1");

            // then
            assertSame(node.Entity(), concurrentNode);
            assertFalse(node.WasCreated());
            verify(index).get("key1", "value1");
            verify(index).putIfAbsent(createdNode, "key1", "value1");
            verify(graphdb, times(1)).createNode();
            verify(tx).success();
        }
Пример #2
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public java.util.concurrent.Future<org.neo4j.graphdb.Node> getOrCreate(final String key, final Object value, final Object initialValue)
        public virtual Future <Node> GetOrCreate(string key, object value, object initialValue)
        {
            return(ExecuteDontWait(StateConflict =>
            {
                UniqueFactory.UniqueNodeFactory factory = new UniqueNodeFactoryAnonymousInnerClass(this, StateConflict.index, key, initialValue);
                return factory.getOrCreate(key, value);
            }));
        }