Search in sources :

Example 1 with DummyEventStore

use of com.alibaba.otter.canal.sink.stub.DummyEventStore in project canal by alibaba.

the class GroupEventSinkTest method testGroupTwo.

@Test
public void testGroupTwo() {
    final DummyEventStore eventStore = new DummyEventStore();
    final GroupEventSink eventSink = new GroupEventSink(3);
    eventSink.setFilterTransactionEntry(true);
    eventSink.setEventStore(eventStore);
    eventSink.start();
    ExecutorService executor = Executors.newFixedThreadPool(3);
    final CountDownLatch latch = new CountDownLatch(1);
    executor.submit(new Runnable() {

        public void run() {
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 1L + i)), address, "ljhtest1");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest1");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("one sink finished!");
            latch.countDown();
        }
    });
    executor.submit(new Runnable() {

        public void run() {
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 10L + i)), address, "ljhtest2");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            for (int i = 0; i < 50; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 40L + i)), address, "ljhtest2");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("tow sink finished!");
            latch.countDown();
        }
    });
    executor.submit(new Runnable() {

        public void run() {
            for (int i = 0; i < 100; i++) {
                try {
                    eventSink.sink(Arrays.asList(buildEntry("1", 1L + i, 30L + i)), address, "ljhtest3");
                    Thread.sleep(50L + RandomUtils.nextInt(50));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            System.out.println("tow sink finished!");
            latch.countDown();
        }
    });
    try {
        latch.await();
        Thread.sleep(200L);
    } catch (InterruptedException e) {
    }
    eventSink.stop();
    executor.shutdownNow();
}
Also used : GroupEventSink(com.alibaba.otter.canal.sink.entry.group.GroupEventSink) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) DummyEventStore(com.alibaba.otter.canal.sink.stub.DummyEventStore) Test(org.junit.Test)

Aggregations

GroupEventSink (com.alibaba.otter.canal.sink.entry.group.GroupEventSink)1 DummyEventStore (com.alibaba.otter.canal.sink.stub.DummyEventStore)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.Test)1