Search in sources :

Example 46 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class TestDbusEventBufferMult method testConstructFilters.

@Test
public void testConstructFilters() throws Exception {
    TestSetup t = new TestSetup();
    //test single Physical Partition subscription
    DatabusSubscription sub1 = DatabusSubscription.createPhysicalPartitionReplicationSubscription(new PhysicalPartition(100, "multBufferTest1"));
    DbusFilter filter1 = t._eventBuffer.constructFilters(Arrays.asList(sub1));
    assertNotNull(filter1);
    assertTrue(filter1 instanceof PhysicalPartitionDbusFilter);
    PhysicalPartitionDbusFilter ppfilter1 = (PhysicalPartitionDbusFilter) filter1;
    assertEquals(ppfilter1.getPhysicalPartition(), new PhysicalPartition(100, "multBufferTest1"));
    assertNull(ppfilter1.getNestedFilter());
    DatabusSubscription sub2 = DatabusSubscription.createPhysicalPartitionReplicationSubscription(new PhysicalPartition(101, "multBufferTest2"));
    //test two Physical Partition subscriptions
    DbusFilter filter2 = t._eventBuffer.constructFilters(Arrays.asList(sub1, sub2));
    assertNotNull(filter2);
    assertTrue(filter2 instanceof ConjunctionDbusFilter);
    ConjunctionDbusFilter conjFilter2 = (ConjunctionDbusFilter) filter2;
    boolean hasPP100 = false;
    boolean hasPP101 = false;
    assertEquals(conjFilter2.getFilterList().size(), 2);
    for (DbusFilter f : conjFilter2.getFilterList()) {
        assertTrue(f instanceof PhysicalPartitionDbusFilter);
        PhysicalPartitionDbusFilter ppf = (PhysicalPartitionDbusFilter) f;
        if (ppf.getPhysicalPartition().getId() == 100)
            hasPP100 = true;
        else if (ppf.getPhysicalPartition().getId() == 101)
            hasPP101 = true;
        else
            fail("unknown physical partition filter:" + ppf.getPhysicalPartition());
    }
    assertTrue(hasPP100);
    assertTrue(hasPP101);
    //test a subcription with a logical source
    DatabusSubscription sub3 = DatabusSubscription.createSimpleSourceSubscription(new LogicalSource(2, "srcName2"));
    DbusFilter filter3 = t._eventBuffer.constructFilters(Arrays.asList(sub3));
    assertNotNull(filter3);
    assertTrue(filter3 instanceof PhysicalPartitionDbusFilter);
    PhysicalPartitionDbusFilter ppfilter3 = (PhysicalPartitionDbusFilter) filter3;
    assertEquals(ppfilter3.getPhysicalPartition(), PhysicalPartition.ANY_PHYSICAL_PARTITION);
    DbusFilter ppfilter3_child = ppfilter3.getNestedFilter();
    assertNotNull(ppfilter3_child);
    assertTrue(ppfilter3_child instanceof LogicalSourceAndPartitionDbusFilter);
    LogicalSourceAndPartitionDbusFilter lsourceFilter3 = (LogicalSourceAndPartitionDbusFilter) ppfilter3_child;
    LogicalSourceAndPartitionDbusFilter.LogicalPartitionDbusFilter lpartFilter3_1 = lsourceFilter3.getSourceFilter(2);
    assertNotNull(lpartFilter3_1);
    assertTrue(lpartFilter3_1.isAllPartitionsWildcard());
    //test a subcription with a physical and logical partition
    DatabusSubscription sub4 = new DatabusSubscription(PhysicalSource.MASTER_PHISYCAL_SOURCE, new PhysicalPartition(101, "multBufferTest2"), new LogicalSourceId(new LogicalSource(2, "srcName2"), (short) 2));
    DbusFilter filter4 = t._eventBuffer.constructFilters(Arrays.asList(sub4));
    assertNotNull(filter4);
    assertTrue(filter4 instanceof PhysicalPartitionDbusFilter);
    PhysicalPartitionDbusFilter ppfilter4 = (PhysicalPartitionDbusFilter) filter4;
    assertEquals(ppfilter4.getPhysicalPartition(), new PhysicalPartition(101, "multBufferTest2"));
    DbusFilter ppfilter4_child = ppfilter4.getNestedFilter();
    assertNotNull(ppfilter4_child);
    assertTrue(ppfilter4_child instanceof LogicalSourceAndPartitionDbusFilter);
    LogicalSourceAndPartitionDbusFilter lsourceFilter4 = (LogicalSourceAndPartitionDbusFilter) ppfilter4_child;
    LogicalSourceAndPartitionDbusFilter.LogicalPartitionDbusFilter lpartFilter4_1 = lsourceFilter4.getSourceFilter(2);
    assertNotNull(lpartFilter4_1);
    assertTrue(lpartFilter4_1.getPartitionsMask().contains(2));
}
Also used : PhysicalPartitionDbusFilter(com.linkedin.databus2.core.filter.PhysicalPartitionDbusFilter) ConjunctionDbusFilter(com.linkedin.databus2.core.filter.ConjunctionDbusFilter) LogicalSourceId(com.linkedin.databus.core.data_model.LogicalSourceId) LogicalSourceAndPartitionDbusFilter(com.linkedin.databus2.core.filter.LogicalSourceAndPartitionDbusFilter) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource) DatabusSubscription(com.linkedin.databus.core.data_model.DatabusSubscription) ConjunctionDbusFilter(com.linkedin.databus2.core.filter.ConjunctionDbusFilter) SourceDbusFilter(com.linkedin.databus2.core.filter.SourceDbusFilter) AllowAllDbusFilter(com.linkedin.databus2.core.filter.AllowAllDbusFilter) LogicalSourceAndPartitionDbusFilter(com.linkedin.databus2.core.filter.LogicalSourceAndPartitionDbusFilter) PhysicalPartitionDbusFilter(com.linkedin.databus2.core.filter.PhysicalPartitionDbusFilter) DbusFilter(com.linkedin.databus2.core.filter.DbusFilter) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 47 with PhysicalPartition

use of com.linkedin.databus.core.data_model.PhysicalPartition in project databus by linkedin.

the class TestPhysicalPartition method testSimpleStringDeserialization.

@Test
public void testSimpleStringDeserialization() {
    PhysicalPartition p1 = new PhysicalPartition(10, "testdb");
    PhysicalPartition p1test = PhysicalPartition.createFromSimpleString(p1.toSimpleString());
    Assert.assertEquals(p1test, p1);
    PhysicalPartition p2 = PhysicalPartition.createAnyPartitionWildcard("somedb");
    PhysicalPartition p2test = PhysicalPartition.createFromSimpleString(p2.toSimpleString());
    Assert.assertEquals(p2test, p2);
    PhysicalPartition p2test2 = PhysicalPartition.createFromSimpleString("somedb");
    Assert.assertEquals(p2test2, p2);
}
Also used : PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) Test(org.testng.annotations.Test)

Aggregations

PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)47 Test (org.testng.annotations.Test)22 BeforeTest (org.testng.annotations.BeforeTest)13 DbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.DbusEventsStatisticsCollector)8 PhysicalPartitionKey (com.linkedin.databus.core.DbusEventBufferMult.PhysicalPartitionKey)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 DatabusSubscription (com.linkedin.databus.core.data_model.DatabusSubscription)6 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)6 AllowAllDbusFilter (com.linkedin.databus2.core.filter.AllowAllDbusFilter)6 EventProducer (com.linkedin.databus2.producers.EventProducer)6 RelayEventProducer (com.linkedin.databus2.producers.RelayEventProducer)6 OracleEventProducer (com.linkedin.databus2.producers.db.OracleEventProducer)6 HashMap (java.util.HashMap)6 DbusEventsTotalStats (com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats)5 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 DbusEventBufferMult (com.linkedin.databus.core.DbusEventBufferMult)4 AggregatedDbusEventsStatisticsCollector (com.linkedin.databus.core.monitoring.mbean.AggregatedDbusEventsStatisticsCollector)4 ConjunctionDbusFilter (com.linkedin.databus2.core.filter.ConjunctionDbusFilter)4 DbusFilter (com.linkedin.databus2.core.filter.DbusFilter)4