Search in sources :

Example 11 with KeyFilterConfigHolder

use of com.linkedin.databus2.core.filter.KeyFilterConfigHolder in project databus by linkedin.

the class TestDbusKeyCompositeFilter method testDbusKeyModFilterWithStringKeys1.

@Test
public // Case when string keys have numeric values
void testDbusKeyModFilterWithStringKeys1() throws Exception {
    KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
    partConf.setType("MOD");
    KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
    modConf.setNumBuckets(100);
    modConf.setBuckets("[0,3-4]");
    partConf.setMod(modConf);
    DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    // String Keys with numeric values
    List<DbusEvent> dbusEvents = new ArrayList<DbusEvent>();
    List<String> keys = new ArrayList<String>();
    for (long i = 0; i < 1000; ++i) {
        keys.add(new Long(i).toString());
    }
    generateStringEvents(1000, (short) 1, keys, dbusEvents);
    List<DbusEvent> expPassedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> expFailedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        long bkt = new Long(new String(event.keyBytes())) % 100;
        if ((bkt == 0) || ((bkt >= 3) && (bkt < 5)))
            expPassedEvents.add(event);
        else
            expFailedEvents.add(event);
    }
    List<DbusEvent> passedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> failedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        if (filter.allow(event)) {
            passedEvents.add(event);
        } else {
            failedEvents.add(event);
        }
    }
    System.out.println("Passed Event Size :" + passedEvents.size());
    System.out.println("Failed Event Size :" + failedEvents.size());
    assertEquals("Passed Size", expPassedEvents.size(), passedEvents.size());
    assertEquals("Failed Size", expFailedEvents.size(), failedEvents.size());
    for (int i = 0; i < passedEvents.size(); ++i) {
        assertEquals("Passed Element " + i, expPassedEvents.get(i), passedEvents.get(i));
    }
    for (int i = 0; i < passedEvents.size(); ++i) {
        assertEquals("Failed Element " + i, expFailedEvents.get(i), failedEvents.get(i));
    }
    ObjectMapper objMapper = new ObjectMapper();
    String objStr = objMapper.writeValueAsString(filter);
    System.out.println("KeyModFilter :" + objStr);
    DbusKeyFilter filter2 = KeyFilterConfigJSONFactory.parseDbusKeyFilter(objStr);
    String objStr2 = objMapper.writeValueAsString(filter2);
    System.out.println("KeyModFilter2 :" + objStr2);
    assertEquals("KeyModFilter JSON Serialization Test", objStr, objStr2);
}
Also used : KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) ArrayList(java.util.ArrayList) DbusKeyFilter(com.linkedin.databus2.core.filter.DbusKeyFilter) KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 12 with KeyFilterConfigHolder

use of com.linkedin.databus2.core.filter.KeyFilterConfigHolder in project databus by linkedin.

the class TestDbusKeyCompositeFilter method testDbusKeyModFilterWithStringKeys2.

@Test
public // Case when string keys have non-numeric values
void testDbusKeyModFilterWithStringKeys2() throws Exception {
    KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
    partConf.setType("MOD");
    KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
    modConf.setNumBuckets(100);
    modConf.setBuckets("[0,3-4]");
    partConf.setMod(modConf);
    DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    // String Keys with numeric values
    List<DbusEvent> dbusEvents = new ArrayList<DbusEvent>();
    List<String> keys = new ArrayList<String>();
    for (long i = 0; i < 1000; ++i) {
        //contains non-numeric char
        keys.add(i + "_1000");
    }
    generateStringEvents(1000, (short) 1, keys, dbusEvents);
    List<DbusEvent> expPassedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> expFailedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        long bkt = new Long(Math.abs(new String(event.keyBytes()).hashCode())) % 100;
        if ((bkt == 0) || ((bkt >= 3) && (bkt < 5)))
            expPassedEvents.add(event);
        else
            expFailedEvents.add(event);
    }
    List<DbusEvent> passedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> failedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        if (filter.allow(event)) {
            passedEvents.add(event);
        } else {
            failedEvents.add(event);
        }
    }
    System.out.println("Passed Event Size :" + passedEvents.size());
    System.out.println("Failed Event Size :" + failedEvents.size());
    assertEquals("Passed Size", expPassedEvents.size(), passedEvents.size());
    assertEquals("Failed Size", expFailedEvents.size(), failedEvents.size());
    for (int i = 0; i < passedEvents.size(); ++i) {
        assertEquals("Passed Element " + i, expPassedEvents.get(i), passedEvents.get(i));
    }
    for (int i = 0; i < passedEvents.size(); ++i) {
        assertEquals("Failed Element " + i, expFailedEvents.get(i), failedEvents.get(i));
    }
    ObjectMapper objMapper = new ObjectMapper();
    String objStr = objMapper.writeValueAsString(filter);
    System.out.println("KeyModFilter :" + objStr);
    DbusKeyFilter filter2 = KeyFilterConfigJSONFactory.parseDbusKeyFilter(objStr);
    String objStr2 = objMapper.writeValueAsString(filter2);
    System.out.println("KeyModFilter2 :" + objStr2);
    assertEquals("KeyModFilter JSON Serialization Test", objStr, objStr2);
}
Also used : KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) ArrayList(java.util.ArrayList) DbusKeyFilter(com.linkedin.databus2.core.filter.DbusKeyFilter) KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 13 with KeyFilterConfigHolder

use of com.linkedin.databus2.core.filter.KeyFilterConfigHolder in project databus by linkedin.

the class TestDbusKeyCompositeFilter method testDbusKeyModFilter.

@Test
public void testDbusKeyModFilter() throws Exception {
    KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
    partConf.setType("MOD");
    KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
    modConf.setNumBuckets(100);
    modConf.setBuckets("[0,3-4]");
    partConf.setMod(modConf);
    DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    List<DbusEvent> dbusEvents = new ArrayList<DbusEvent>();
    List<Long> keys = new ArrayList<Long>();
    for (long i = 0; i < 1000; i++) {
        keys.add(i);
    }
    generateEvents(1000, (short) 1, keys, dbusEvents);
    List<DbusEvent> expPassedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> expFailedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        long bkt = event.key() % 100;
        if ((bkt == 0) || ((bkt >= 3) && (bkt < 5)))
            expPassedEvents.add(event);
        else
            expFailedEvents.add(event);
    }
    List<DbusEvent> passedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> failedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        if (filter.allow(event)) {
            passedEvents.add(event);
        } else {
            failedEvents.add(event);
        }
    }
    System.out.println("Passed Event Size :" + passedEvents.size());
    System.out.println("Failed Event Size :" + failedEvents.size());
    assertEquals("Passed Size", expPassedEvents.size(), passedEvents.size());
    assertEquals("Failed Size", expFailedEvents.size(), failedEvents.size());
    for (int i = 0; i < passedEvents.size(); ++i) {
        assertEquals("Passed Element " + i, expPassedEvents.get(i), passedEvents.get(i));
    }
    for (int i = 0; i < passedEvents.size(); ++i) {
        assertEquals("Failed Element " + i, expFailedEvents.get(i), failedEvents.get(i));
    }
    ObjectMapper objMapper = new ObjectMapper();
    String objStr = objMapper.writeValueAsString(filter);
    System.out.println("KeyModFilter :" + objStr);
    DbusKeyFilter filter2 = KeyFilterConfigJSONFactory.parseDbusKeyFilter(objStr);
    String objStr2 = objMapper.writeValueAsString(filter2);
    System.out.println("KeyModFilter2 :" + objStr2);
    assertEquals("KeyModFilter JSON Serialization Test", objStr, objStr2);
}
Also used : KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) ArrayList(java.util.ArrayList) DbusKeyFilter(com.linkedin.databus2.core.filter.DbusKeyFilter) KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 14 with KeyFilterConfigHolder

use of com.linkedin.databus2.core.filter.KeyFilterConfigHolder in project databus by linkedin.

the class TestDbusKeyCompositeFilter method testDbusKeyNoneFilter.

@Test
public void testDbusKeyNoneFilter() throws Exception {
    KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
    partConf.setType("NONE");
    DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
    List<DbusEvent> dbusEvents = new ArrayList<DbusEvent>();
    List<Long> keys = new ArrayList<Long>();
    for (long i = 0; i < 1000; i++) {
        keys.add(i);
    }
    generateEvents(1000, (short) 1, keys, dbusEvents);
    List<DbusEvent> passedEvents = new ArrayList<DbusEvent>();
    List<DbusEvent> failedEvents = new ArrayList<DbusEvent>();
    for (DbusEvent event : dbusEvents) {
        if (filter.allow(event)) {
            passedEvents.add(event);
        } else {
            failedEvents.add(event);
        }
    }
    System.out.println("Passed Event Size :" + passedEvents.size());
    System.out.println("Failed Event Size :" + failedEvents.size());
    assertEquals("Passed Size", dbusEvents.size(), passedEvents.size());
    assertEquals("Failed Size", 0, failedEvents.size());
    for (int i = 0; i < passedEvents.size(); i++) {
        assertEquals("Passed Element " + i, dbusEvents.get(i), passedEvents.get(i));
    }
    ObjectMapper objMapper = new ObjectMapper();
    String objStr = objMapper.writeValueAsString(filter);
    System.out.println("KeyFilter :" + objStr);
    DbusKeyFilter filter2 = KeyFilterConfigJSONFactory.parseDbusKeyFilter(objStr);
    String objStr2 = objMapper.writeValueAsString(filter2);
    System.out.println("KeyFilter2 :" + objStr2);
    assertEquals("KeyNoneFilter: JSON Serialization Test", objStr, objStr2);
}
Also used : KeyModFilterConfig(com.linkedin.databus2.core.filter.KeyModFilterConfig) KeyRangeFilterConfig(com.linkedin.databus2.core.filter.KeyRangeFilterConfig) ArrayList(java.util.ArrayList) DbusKeyFilter(com.linkedin.databus2.core.filter.DbusKeyFilter) KeyFilterConfigHolder(com.linkedin.databus2.core.filter.KeyFilterConfigHolder) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Aggregations

KeyFilterConfigHolder (com.linkedin.databus2.core.filter.KeyFilterConfigHolder)14 DbusKeyFilter (com.linkedin.databus2.core.filter.DbusKeyFilter)13 Test (org.testng.annotations.Test)12 KeyModFilterConfig (com.linkedin.databus2.core.filter.KeyModFilterConfig)10 KeyRangeFilterConfig (com.linkedin.databus2.core.filter.KeyRangeFilterConfig)10 ArrayList (java.util.ArrayList)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 DbusKeyCompositeFilter (com.linkedin.databus2.core.filter.DbusKeyCompositeFilter)4 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)3 HashMap (java.util.HashMap)3 BootstrapConfig (com.linkedin.databus.bootstrap.common.BootstrapConfig)2 BootstrapReadOnlyConfig (com.linkedin.databus.bootstrap.common.BootstrapReadOnlyConfig)2 BootstrapServerConfig (com.linkedin.databus.bootstrap.server.BootstrapServerConfig)2 BootstrapServerStaticConfig (com.linkedin.databus.bootstrap.server.BootstrapServerStaticConfig)2 Checkpoint (com.linkedin.databus.core.Checkpoint)2 IdNamePair (com.linkedin.databus.core.util.IdNamePair)2 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)2 CheckpointMult (com.linkedin.databus.core.CheckpointMult)1 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)1 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)1