示例#1
0
        internal static void AssertKeyIsMap(ResourceIterator <IDictionary <string, object> > r, string keyKey, string valueKey, MapValue expected)
        {
            IList <IDictionary <string, object> > result = r.ToList();

            assertEquals("Results for should have size " + expected.Size() + " but was " + result.Count, expected.Size(), result.Count);

            foreach (IDictionary <string, object> row in result)
            {
                TextValue key = ( TextValue )row[keyKey];
                assertTrue(expected.ContainsKey(key.StringValue()));
                assertThat(row, hasKey(valueKey));

                object objectValue = row[valueKey];
                if (objectValue is ListValue)
                {
                    ListValue value          = ( ListValue )objectValue;
                    ListValue expectedValues = ( ListValue )expected.Get(key.StringValue());
                    assertEquals("sizes", value.Size(), expectedValues.Size());
                    assertThat(Arrays.asList(value.AsArray()), containsInAnyOrder(expectedValues.AsArray()));
                }
                else
                {
                    string value         = (( TextValue )objectValue).stringValue();
                    string expectedValue = (( TextValue )expected.Get(key.StringValue())).stringValue();
                    assertThat(value, equalTo(expectedValue));
                }
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeNotificationsIfPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncludeNotificationsIfPresent()
        {
            // Given
            QueryResult result = mock(typeof(QueryResult));

            when(result.FieldNames()).thenReturn(new string[0]);

            QueryStatistics queryStatistics = mock(typeof(QueryStatistics));

            when(queryStatistics.ContainsUpdates()).thenReturn(false);

            when(result.QueryStatistics()).thenReturn(queryStatistics);
            when(result.ExecutionType()).thenReturn(query(READ_WRITE));

            when(result.Notifications).thenReturn(Arrays.asList(NotificationCode.INDEX_HINT_UNFULFILLABLE.notification(InputPosition.empty), NotificationCode.PLANNER_UNSUPPORTED.notification(new InputPosition(4, 5, 6))));
            TransactionalContext tc     = mock(typeof(TransactionalContext));
            CypherAdapterStream  stream = new CypherAdapterStream(result, Clock.systemUTC());

            // When
            MapValue meta = MetadataOf(stream);

            // Then
            MapValue msg1 = MapValues("severity", stringValue("WARNING"), "code", stringValue("Neo.ClientError.Schema.IndexNotFound"), "title", stringValue("The request (directly or indirectly) referred to an index that does not exist."), "description", stringValue("The hinted index does not exist, please check the schema"));
            MapValue msg2 = MapValues("severity", stringValue("WARNING"), "code", stringValue("Neo.ClientNotification.Statement.PlannerUnsupportedWarning"), "title", stringValue("This query is not supported by the COST planner."), "description", stringValue("Using COST planner is unsupported for this query, please use RULE planner instead"), "position", MapValues("offset", intValue(4), "column", intValue(6), "line", intValue(5)));

            assertThat(meta.Get("notifications"), equalTo(list(msg1, msg2)));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeProfileIfPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncludeProfileIfPresent()
        {
            // Given
            QueryStatistics queryStatistics = mock(typeof(QueryStatistics));

            when(queryStatistics.ContainsUpdates()).thenReturn(false);
            QueryResult result = mock(typeof(QueryResult));

            when(result.FieldNames()).thenReturn(new string[0]);
            when(result.ExecutionType()).thenReturn(explained(READ_ONLY));
            when(result.QueryStatistics()).thenReturn(queryStatistics);
            when(result.Notifications).thenReturn(Collections.emptyList());
            when(result.ExecutionPlanDescription()).thenReturn(Plan("Join", map("arg1", 1), 2, 4, 3, 1, singletonList("id1"), Plan("Scan", map("arg2", 1), 2, 4, 7, 1, singletonList("id2"))));

            TransactionalContext tc     = mock(typeof(TransactionalContext));
            CypherAdapterStream  stream = new CypherAdapterStream(result, Clock.systemUTC());

            // When
            MapValue meta = MetadataOf(stream);

            // Then
            MapValue expectedChild = MapValues("args", MapValues("arg2", intValue(1)), "identifiers", list(stringValue("id2")), "operatorType", stringValue("Scan"), "children", VirtualValues.EMPTY_LIST, "rows", longValue(1L), "dbHits", longValue(2L), "pageCacheHits", longValue(4L), "pageCacheMisses", longValue(7L), "pageCacheHitRatio", doubleValue(4.0 / 11));

            MapValue expectedProfile = MapValues("args", MapValues("arg1", intValue(1)), "identifiers", list(stringValue("id1")), "operatorType", stringValue("Join"), "children", list(expectedChild), "rows", longValue(1L), "dbHits", longValue(2L), "pageCacheHits", longValue(4L), "pageCacheMisses", longValue(3L), "pageCacheHitRatio", doubleValue(4.0 / 7));

            AssertMapEqualsWithDelta(( MapValue )meta.Get("profile"), expectedProfile, 0.0001);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludePlanIfPresent() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncludePlanIfPresent()
        {
            // Given
            QueryStatistics queryStatistics = mock(typeof(QueryStatistics));

            when(queryStatistics.ContainsUpdates()).thenReturn(false);
            QueryResult result = mock(typeof(QueryResult));

            when(result.FieldNames()).thenReturn(new string[0]);
            when(result.ExecutionType()).thenReturn(explained(READ_ONLY));
            when(result.QueryStatistics()).thenReturn(queryStatistics);
            when(result.Notifications).thenReturn(Collections.emptyList());
            when(result.ExecutionPlanDescription()).thenReturn(Plan("Join", map("arg1", 1), singletonList("id1"), Plan("Scan", map("arg2", 1), singletonList("id2"))));

            TransactionalContext tc     = mock(typeof(TransactionalContext));
            CypherAdapterStream  stream = new CypherAdapterStream(result, Clock.systemUTC());

            // When
            MapValue meta = MetadataOf(stream);

            // Then
            MapValue expectedChild = MapValues("args", MapValues("arg2", intValue(1)), "identifiers", list(stringValue("id2")), "operatorType", stringValue("Scan"), "children", VirtualValues.EMPTY_LIST);
            MapValue expectedPlan  = MapValues("args", MapValues("arg1", intValue(1)), "identifiers", list(stringValue("id1")), "operatorType", stringValue("Join"), "children", list(expectedChild));

            assertThat(meta.Get("plan"), equalTo(expectedPlan));
        }
示例#5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static Bookmark parseMultipleBookmarks(org.neo4j.values.virtual.MapValue params) throws BookmarkFormatException
        private static Bookmark ParseMultipleBookmarks(MapValue @params)
        {
            AnyValue bookmarksObject = @params.Get(BOOKMARKS_KEY);

            if (bookmarksObject == Values.NO_VALUE)
            {
                return(null);
            }
            else if (bookmarksObject is ListValue)
            {
                ListValue bookmarks = ( ListValue )bookmarksObject;

                long maxTxId = -1;
                foreach (AnyValue bookmark in bookmarks)
                {
                    if (bookmark != Values.NO_VALUE)
                    {
                        long txId = TxIdFrom(bookmark);
                        if (txId > maxTxId)
                        {
                            maxTxId = txId;
                        }
                    }
                }
                return(maxTxId == -1 ? null : new Bookmark(maxTxId));
            }
            else
            {
                throw new BookmarkFormatException(bookmarksObject);
            }
        }
示例#6
0
        public static TimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            OffsetTime time        = input.getTimePart(defaultZone);
            OffsetTime truncatedOT = AssertValidUnit(() => time.truncatedTo(unit));

            if (fields.Size() == 0)
            {
                return(time(truncatedOT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    ZonedDateTime currentDT     = AssertValidArgument(() => ZonedDateTime.ofInstant(Instant.now(), TimezoneOf(timezone)));
                    ZoneOffset    currentOffset = currentDT.Offset;
                    truncatedOT = truncatedOT.withOffsetSameLocal(currentOffset);
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedOT, (mapValue, offsetTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return time(offsetTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("time", time(offsetTime)), defaultZone);
                    }
                }));
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") public static Object mapGetProperty(Object object, String key)
        public static object MapGetProperty(object @object, string key)
        {
            if (@object == NO_VALUE)
            {
                return(NO_VALUE);
            }
            if (@object is MapValue)
            {
                MapValue map = ( MapValue )@object;
                return(map.Get(key));
            }
            if (@object is NodeProxyWrappingNodeValue)
            {
                return(Values.of((( NodeProxyWrappingNodeValue )@object).nodeProxy().getProperty(key)));
            }
            if (@object is RelationshipProxyWrappingValue)
            {
                return(Values.of((( RelationshipProxyWrappingValue )@object).relationshipProxy().getProperty(key)));
            }
            if (@object is PropertyContainer)                 // Entity that is not wrapped by an AnyValue
            {
                return(Values.of((( PropertyContainer )@object).getProperty(key)));
            }
            if (@object is NodeValue)
            {
                return((( NodeValue )@object).properties().get(key));
            }
            if (@object is RelationshipValue)
            {
                return((( RelationshipValue )@object).properties().get(key));
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (object instanceof java.util.Map<?,?>)
            if (@object is IDictionary <object, ?> )
            {
                IDictionary <string, object> map = (IDictionary <string, object>)@object;
                return(map[key]);
            }
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: if (object instanceof org.neo4j.values.storable.TemporalValue<?,?>)
            if (@object is TemporalValue <object, ?> )
            {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: return ((org.neo4j.values.storable.TemporalValue<?,?>) object).get(key);
                return(((TemporalValue <object, ?>)@object).get(key));
            }
            if (@object is DurationValue)
            {
                return((( DurationValue )@object).get(key));
            }
            if (@object is PointValue)
            {
                return((( PointValue )@object).get(key));
            }

            // NOTE: VirtualNodeValue and VirtualRelationshipValue will fall through to here
            // To handle these we would need specialized cursor code
            throw new CypherTypeException(string.Format("Type mismatch: expected a map but was {0}", @object), null);
        }
示例#8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void profileStatisticConversion()
        public virtual void ProfileStatisticConversion()
        {
            MapValue convertedMap = ExecutionPlanConverter.Convert(new TestExecutionPlanDescription(this, "description", ProfilerStatistics, Identifiers, Arguments));

            assertEquals(convertedMap.Get("operatorType"), stringValue("description"));
            assertEquals(convertedMap.Get("args"), ValueUtils.asMapValue(Arguments));
            assertEquals(convertedMap.Get("identifiers"), ValueUtils.asListValue(Identifiers));
            assertEquals(convertedMap.Get("children"), VirtualValues.EMPTY_LIST);
            assertEquals(convertedMap.Get("rows"), longValue(1L));
            assertEquals(convertedMap.Get("dbHits"), longValue(2L));
            assertEquals(convertedMap.Get("pageCacheHits"), longValue(3L));
            assertEquals(convertedMap.Get("pageCacheMisses"), longValue(2L));
            assertEquals((( DoubleValue )convertedMap.Get("pageCacheHitRatio")).doubleValue(), 3.0 / 5, 0.0001);
            assertEquals(convertedMap.Size(), 9);
        }
示例#9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static Bookmark parseSingleBookmark(org.neo4j.values.virtual.MapValue params) throws BookmarkFormatException
        private static Bookmark ParseSingleBookmark(MapValue @params)
        {
            AnyValue bookmarkObject = @params.Get(BOOKMARK_KEY);

            if (bookmarkObject == Values.NO_VALUE)
            {
                return(null);
            }

            return(new Bookmark(TxIdFrom(bookmarkObject)));
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncludeBasicMetadata() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIncludeBasicMetadata()
        {
            // Given
            QueryStatistics queryStatistics = mock(typeof(QueryStatistics));

            when(queryStatistics.ContainsUpdates()).thenReturn(true);
            when(queryStatistics.NodesCreated).thenReturn(1);
            when(queryStatistics.NodesDeleted).thenReturn(2);
            when(queryStatistics.RelationshipsCreated).thenReturn(3);
            when(queryStatistics.RelationshipsDeleted).thenReturn(4);
            when(queryStatistics.PropertiesSet).thenReturn(5);
            when(queryStatistics.IndexesAdded).thenReturn(6);
            when(queryStatistics.IndexesRemoved).thenReturn(7);
            when(queryStatistics.ConstraintsAdded).thenReturn(8);
            when(queryStatistics.ConstraintsRemoved).thenReturn(9);
            when(queryStatistics.LabelsAdded).thenReturn(10);
            when(queryStatistics.LabelsRemoved).thenReturn(11);

            QueryResult result = mock(typeof(QueryResult));

            when(result.FieldNames()).thenReturn(new string[0]);
            when(result.ExecutionType()).thenReturn(query(READ_WRITE));
            when(result.QueryStatistics()).thenReturn(queryStatistics);
            when(result.Notifications).thenReturn(Collections.emptyList());

            Clock clock = mock(typeof(Clock));

            when(clock.millis()).thenReturn(0L, 1337L);

            TransactionalContext tc     = mock(typeof(TransactionalContext));
            CypherAdapterStream  stream = new CypherAdapterStream(result, clock);

            // When
            MapValue meta = MetadataOf(stream);

            // Then
            assertThat(meta.Get("type"), equalTo(stringValue("rw")));
            assertThat(meta.Get("stats"), equalTo(MapValues("nodes-created", intValue(1), "nodes-deleted", intValue(2), "relationships-created", intValue(3), "relationships-deleted", intValue(4), "properties-set", intValue(5), "indexes-added", intValue(6), "indexes-removed", intValue(7), "constraints-added", intValue(8), "constraints-removed", intValue(9), "labels-added", intValue(10), "labels-removed", intValue(11))));
            assertThat(meta.Get("result_consumed_after"), equalTo(longValue(1337L)));
        }
示例#11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleMaps()
        internal virtual void ShouldHandleMaps()
        {
            // Given
            IDictionary <string, object> map = MapUtil.map("a", Arrays.asList("foo", 42));

            // When
            AnyValue anyValue = ValueUtils.of(map);

            // Then
            assertThat(anyValue, instanceOf(typeof(MapValue)));
            MapValue mapValue = ( MapValue )anyValue;

            assertThat(mapValue.Get("a"), equalTo(VirtualValues.list(stringValue("foo"), intValue(42))));
            assertThat(mapValue.Size(), equalTo(1));
        }
示例#12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static java.time.Duration parseTransactionTimeout(org.neo4j.values.virtual.MapValue meta) throws org.neo4j.bolt.messaging.BoltIOException
        internal static Duration ParseTransactionTimeout(MapValue meta)
        {
            AnyValue anyValue = meta.Get(TX_TIMEOUT_KEY);

            if (anyValue == Values.NO_VALUE)
            {
                return(null);
            }
            else if (anyValue is LongValue)
            {
                return(Duration.ofMillis((( LongValue )anyValue).longValue()));
            }
            else
            {
                throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Expecting transaction timeout value to be a Long value, but got: " + anyValue);
            }
        }
示例#13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static java.util.Map<String,Object> parseTransactionMetadata(org.neo4j.values.virtual.MapValue meta) throws org.neo4j.bolt.messaging.BoltIOException
        internal static IDictionary <string, object> ParseTransactionMetadata(MapValue meta)
        {
            AnyValue anyValue = meta.Get(TX_META_DATA_KEY);

            if (anyValue == Values.NO_VALUE)
            {
                return(null);
            }
            else if (anyValue is MapValue)
            {
                MapValue mapValue = ( MapValue )anyValue;
                TransactionMetadataWriter    writer = new TransactionMetadataWriter();
                IDictionary <string, object> txMeta = new Dictionary <string, object>(mapValue.Size());
                mapValue.Foreach((key, value) => txMeta.put(key, writer.ValueAsObject(value)));
                return(txMeta);
            }
            else
            {
                throw new BoltIOException(Org.Neo4j.Kernel.Api.Exceptions.Status_Request.Invalid, "Expecting transaction metadata value to be a Map value, but got: " + anyValue);
            }
        }
示例#14
0
 private static void AssertMapEqualsWithDelta(MapValue a, MapValue b, double delta)
 {
     assertThat("Map should have same size", a.Size(), equalTo(b.Size()));
     a.Foreach((key, value) =>
     {
         AnyValue aValue = value;
         AnyValue bValue = b.Get(key);
         if (aValue is MapValue)
         {
             assertThat("Value mismatch", bValue is MapValue);
             AssertMapEqualsWithDelta(( MapValue )aValue, ( MapValue )bValue, delta);
         }
         else if (aValue is DoubleValue)
         {
             assertThat("Value mismatch", (( DoubleValue )aValue).doubleValue(), closeTo(((DoubleValue)bValue).doubleValue(), delta));
         }
         else
         {
             assertThat("Value mismatch", aValue, equalTo(bValue));
         }
     });
 }
示例#15
0
        public static DateTimeValue Truncate(TemporalUnit unit, TemporalValue input, MapValue fields, System.Func <ZoneId> defaultZone)
        {
            Pair <LocalDate, LocalTime> pair = GetTruncatedDateAndTime(unit, input, "date time");

            LocalDate truncatedDate = pair.First();
            LocalTime truncatedTime = pair.Other();

            ZoneId        zoneId       = input.supportsTimeZone() ? input.getZoneId(defaultZone) : defaultZone();
            ZonedDateTime truncatedZDT = ZonedDateTime.of(truncatedDate, truncatedTime, zoneId);

            if (fields.Size() == 0)
            {
                return(Datetime(truncatedZDT));
            }
            else
            {
                // Timezone needs some special handling, since the builder will shift keeping the instant instead of the local time
                AnyValue timezone = fields.Get("timezone");
                if (timezone != NO_VALUE)
                {
                    truncatedZDT = truncatedZDT.withZoneSameLocal(TimezoneOf(timezone));
                }

                return(UpdateFieldMapWithConflictingSubseconds(fields, unit, truncatedZDT, (mapValue, zonedDateTime) =>
                {
                    if (mapValue.size() == 0)
                    {
                        return Datetime(zonedDateTime);
                    }
                    else
                    {
                        return Build(mapValue.updatedWith("datetime", Datetime(zonedDateTime)), defaultZone);
                    }
                }));
            }
        }