Search in sources :

Example 1 with FilterCu

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.

the class TmfFilterHelperTest method getRegex.

private static Predicate<Multimap<String, Object>> getRegex(ITmfFilter filter, String expected) {
    String regex = TmfFilterHelper.getRegexFromFilter(filter);
    assertEquals(expected, regex);
    FilterCu compile = FilterCu.compile(regex);
    assertNotNull(compile);
    Predicate<Multimap<String, Object>> predicate = compile.generate();
    return predicate;
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) FilterCu(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu)

Example 2 with FilterCu

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.

the class ElementResolverFilterTest method testMatchesOperator.

@Test
public void testMatchesOperator() {
    FilterCu cu = FilterCu.compile("key0 matches v.*ue");
    assertNotNull(cu);
    Predicate<Multimap<String, Object>> predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    // Test with a second value of key0
    cu = FilterCu.compile("key0 matches o.*er");
    assertNotNull(cu);
    predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    cu = FilterCu.compile("key0 matches v.*ue$");
    assertNotNull(cu);
    predicate = cu.generate();
    assertFalse(predicate.test(ELEMENT.getMetadata()));
    cu = FilterCu.compile(" \"key 2\" matches value2");
    assertNotNull(cu);
    predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    cu = FilterCu.compile(" \"key3\" matches 10");
    assertNotNull(cu);
    predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    // Match a number against an hex string
    cu = FilterCu.compile(" \"key3\" matches 0xa");
    assertNotNull(cu);
    predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) FilterCu(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu) Test(org.junit.Test)

Example 3 with FilterCu

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.

the class ElementResolverFilterTest method testFilterWithNumber.

@Test
public void testFilterWithNumber() {
    // Simple number comparison
    FilterCu cu = FilterCu.compile("key3 > 9");
    assertNotNull(cu);
    Predicate<Multimap<String, Object>> predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    assertFalse(predicate.test(ImmutableMultimap.of("key3", 8)));
    // String comparison, "10" < "9a"
    cu = FilterCu.compile("key3 > 9a");
    assertNotNull(cu);
    predicate = cu.generate();
    assertFalse(predicate.test(ELEMENT.getMetadata()));
    // "9b" > "9a"
    assertTrue(predicate.test(ImmutableMultimap.of("key3", "9b")));
    // String comparison with duration numbers
    cu = FilterCu.compile("key3 > 2ms");
    assertNotNull(cu);
    predicate = cu.generate();
    assertFalse(predicate.test(ELEMENT.getMetadata()));
    // Would be smaller as a String, but larger as a Number
    assertTrue(predicate.test(ImmutableMultimap.of("key3", 10000000)));
    // String comparison with decimal with unit numbers
    cu = FilterCu.compile("key3 > 2k");
    assertNotNull(cu);
    predicate = cu.generate();
    assertFalse(predicate.test(ELEMENT.getMetadata()));
    // Would be smaller as a String, but larger as a Number
    assertTrue(predicate.test(ImmutableMultimap.of("key3", 10000000)));
    // String comparison with timestamps
    // For now, only the TTT format works for timestamp comparison, so we
    // first update the time preferences and put it back to its original
    // value at the end
    Map<String, String> defaultPrefMap = TmfTimePreferences.getPreferenceMap();
    IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
    String dateFormat = defaultPrefMap.get(ITmfTimePreferencesConstants.DATIME);
    try {
        defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "TTT.SSS SSS SSS");
        TmfTimestampFormat.updateDefaultFormats();
        long timeValue = 1000000000L;
        String dateString = TmfTimestampFormat.getDefaulTimeFormat().format(timeValue);
        cu = FilterCu.compile("key3 == \"" + dateString + "\"");
        assertNotNull(cu);
        predicate = cu.generate();
        assertFalse(predicate.test(ELEMENT.getMetadata()));
        assertFalse(predicate.test(ImmutableMultimap.of("key3", timeValue + 3)));
        assertTrue(predicate.test(ImmutableMultimap.of("key3", timeValue)));
        // Use another less trivial time value
        timeValue = 1539786952382956759L;
        dateString = TmfTimestampFormat.getDefaulTimeFormat().format(timeValue);
        cu = FilterCu.compile("key3 == \"" + dateString + "\"");
        assertNotNull(cu);
        predicate = cu.generate();
        assertFalse(predicate.test(ELEMENT.getMetadata()));
        assertFalse(predicate.test(ImmutableMultimap.of("key3", timeValue + 3)));
        assertTrue(predicate.test(ImmutableMultimap.of("key3", timeValue)));
    } finally {
        defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, dateFormat);
        TmfTimestampFormat.updateDefaultFormats();
    }
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) FilterCu(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Test(org.junit.Test)

Example 4 with FilterCu

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.

the class ElementResolverFilterTest method testLessThanOperator.

@Test
public void testLessThanOperator() {
    FilterCu cu = FilterCu.compile("key3 < 11");
    assertNotNull(cu);
    Predicate<Multimap<String, Object>> predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    cu = FilterCu.compile("key3 < 10");
    assertNotNull(cu);
    predicate = cu.generate();
    assertFalse(predicate.test(ELEMENT.getMetadata()));
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) FilterCu(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu) Test(org.junit.Test)

Example 5 with FilterCu

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu in project tracecompass by tracecompass.

the class ElementResolverFilterTest method testGreaterThanOperator.

@Test
public void testGreaterThanOperator() {
    FilterCu cu = FilterCu.compile("key3 > 9");
    assertNotNull(cu);
    Predicate<Multimap<String, Object>> predicate = cu.generate();
    assertTrue(predicate.test(ELEMENT.getMetadata()));
    cu = FilterCu.compile("key3 > 10");
    assertNotNull(cu);
    predicate = cu.generate();
    assertFalse(predicate.test(ELEMENT.getMetadata()));
}
Also used : Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) FilterCu(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu) Test(org.junit.Test)

Aggregations

FilterCu (org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu)18 Multimap (com.google.common.collect.Multimap)16 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)14 Test (org.junit.Test)13 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 Predicate (java.util.function.Predicate)4 NonNull (org.eclipse.jdt.annotation.NonNull)4 HashMultimap (com.google.common.collect.HashMultimap)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)1