Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics#toString()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.util.TraversalMetrics#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void validate_g_V_out_out_profile_modern(final Traversal traversal, final TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    assumeThat("The following assertions apply to TinkerGraph only as provider strategies can alter the steps to not comply with expectations",
            graph.getClass().getSimpleName(), equalTo("TinkerGraph"));

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(6, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(2);
    assertEquals(2, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());

    if (!onGraphComputer(traversal.asAdmin())) {
        // Every other step should be a Profile step
        List<Step> steps = traversal.asAdmin().getSteps();
        for (int ii = 1; ii <= 6; ii += 2) {
            assertEquals("Every other Step should be a ProfileStep.", ProfileStep.class, steps.get(ii).getClass());
        }
    }
}
 
Example 2
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void validate_g_V_sideEffectXThread_sleepX10XX_sideEffectXThread_sleepX5XX_profile(final TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    assumeThat("The following assertions apply to TinkerGraph only as provider strategies can alter the steps to not comply with expectations",
            graph.getClass().getSimpleName(), equalTo("TinkerGraph"));

    // Grab the second (sideEffect{sleep}) step and check the times.
    Metrics metrics = traversalMetrics.getMetrics(1);
    // 6 elements w/ a 10ms sleep each = 60ms with 10ms for other computation.
    assertTrue("Duration should be at least the length of the sleep (59ms): " + metrics.getDuration(TimeUnit.MILLISECONDS),
            metrics.getDuration(TimeUnit.MILLISECONDS) >= 59);

    // 6 elements w/ a 5ms sleep each = 30ms plus 20ms for other computation
    metrics = traversalMetrics.getMetrics(2);
    assertTrue("Duration should be at least the length of the sleep (29ms): " + metrics.getDuration(TimeUnit.MILLISECONDS),
            metrics.getDuration(TimeUnit.MILLISECONDS) >= 29);

    double totalPercentDuration = 0;
    for (Metrics m : traversalMetrics.getMetrics()) {
        totalPercentDuration += (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY);
    }
    assertEquals(100, totalPercentDuration, 0.000001);
}
 
Example 3
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void validate_g_V_whereXinXcreatedX_count_isX1XX_name_profile(final Traversal traversal, final TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    assumeThat("The following assertions apply to TinkerGraph only as provider strategies can alter the steps to not comply with expectations",
            graph.getClass().getSimpleName(), equalTo("TinkerGraph"));

    assertEquals("There should be 3 top-level metrics.", 3, traversalMetrics.getMetrics().size());

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(6, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(1, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(1, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());

    if (traversal.asAdmin().getStrategies().getStrategy(CountStrategy.class).isPresent()) {
        assertEquals("Metrics 1 should have 4 nested metrics.", 4, metrics.getNested().size());
    } else {
        assertEquals("Metrics 1 should have 3 nested metrics.", 3, metrics.getNested().size());
    }
}
 
Example 4
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private void validate_g_V_out_out_profile_grateful(final TraversalMetrics traversalMetrics) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    assumeThat("The following assertions apply to TinkerGraph only as provider strategies can alter the steps to not comply with expectations",
            graph.getClass().getSimpleName(), equalTo("TinkerGraph"));

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(808, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(808, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.", (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(8049, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.", (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    metrics = traversalMetrics.getMetrics(2);
    assertEquals(327370, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.", (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    double totalPercentDuration = 0;
    for (Metrics m : traversalMetrics.getMetrics()) {
        totalPercentDuration += (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY);
    }
    assertEquals(100, totalPercentDuration, 0.000001);
}
 
Example 5
Source File: ProfileTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private void validate_g_V_repeat_both_modern_profile(final TraversalMetrics traversalMetrics, final boolean withRepeatUnrollStrategy) {
    traversalMetrics.toString(); // ensure no exceptions are thrown

    assumeThat("The following assertions apply to TinkerGraph only as provider strategies can alter the steps to not comply with expectations",
            graph.getClass().getSimpleName(), equalTo("TinkerGraph"));

    Metrics metrics = traversalMetrics.getMetrics(0);
    assertEquals(6, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertEquals(6, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());

    metrics = traversalMetrics.getMetrics(1);
    assertEquals(withRepeatUnrollStrategy ? 12 : 72, metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
    assertNotEquals(0, metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    if (!withRepeatUnrollStrategy)
        assertTrue("Count should be greater than traversers.", metrics.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > metrics.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
    assertTrue("Percent duration should be positive.", (Double) metrics.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY) >= 0);
    assertTrue("Times should be positive.", metrics.getDuration(TimeUnit.MICROSECONDS) >= 0);

    // Test the nested global metrics of the repeat step
    if (!withRepeatUnrollStrategy) {
        final Metrics vertexStepNestedInRepeat = (Metrics) metrics.getNested().toArray()[0];
        assertEquals(114, vertexStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID).longValue());
        assertNotEquals(0, vertexStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
        assertTrue("Count should be greater than traversers.", vertexStepNestedInRepeat.getCount(TraversalMetrics.ELEMENT_COUNT_ID) > vertexStepNestedInRepeat.getCount(TraversalMetrics.TRAVERSER_COUNT_ID).longValue());
        assertTrue("Times should be positive.", vertexStepNestedInRepeat.getDuration(TimeUnit.MICROSECONDS) >= 0);
    }

    double totalPercentDuration = 0;
    for (Metrics m : traversalMetrics.getMetrics()) {
        totalPercentDuration += (Double) m.getAnnotation(TraversalMetrics.PERCENT_DURATION_KEY);
    }
    assertEquals(100, totalPercentDuration, 0.000001);
}