Search in sources :

Example 26 with Communication

use of com.alibaba.datax.core.statistics.communication.Communication in project DataX by alibaba.

the class TaskGroupContainerTest method testLongTimeWriter.

@Test
public void testLongTimeWriter() {
    this.configuration.set("plugin.writer.fakewriter.class", FakeOneReader.class.getName());
    this.configuration.set("plugin.writer.fakewriter.class", FakeLongTimeWriter.class.getName());
    this.configuration.set(CoreConstant.DATAX_CORE_CONTAINER_TASKGROUP_CHANNEL, 1);
    Configuration jobContent = this.configuration.getListConfiguration(CoreConstant.DATAX_JOB_CONTENT).get(0);
    List<Configuration> jobContents = new ArrayList<Configuration>();
    jobContents.add(jobContent);
    this.configuration.set(CoreConstant.DATAX_JOB_CONTENT, jobContents);
    TaskGroupContainer taskGroupContainer = new TaskGroupContainer(this.configuration);
    taskGroupContainer.start();
    Assert.assertTrue(State.SUCCEEDED == taskGroupContainer.getContainerCommunicator().collect().getState());
    Communication res = null;
    try {
        Method com = TaskGroupContainer.class.getDeclaredMethod("reportTaskGroupCommunication", Communication.class, int.class);
        com.setAccessible(true);
        res = (Communication) com.invoke(taskGroupContainer, new Communication(), 1);
        System.out.println("TaskGroup => " + CommunicationTool.Stringify.getSnapshot(res));
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertTrue(res != null);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TOTAL_READ_RECORDS).longValue(), 40);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_SUCCEED_RECORDS).longValue(), 0);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_FAILED_RECORDS).longValue(), 0);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_FILTER_RECORDS).longValue(), 0);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_USED_TIME).longValue(), 0);
    System.out.println(res.getMessage());
}
Also used : TaskGroupContainer(com.alibaba.datax.core.taskgroup.TaskGroupContainer) Configuration(com.alibaba.datax.common.util.Configuration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Communication(com.alibaba.datax.core.statistics.communication.Communication) Test(org.junit.Test)

Example 27 with Communication

use of com.alibaba.datax.core.statistics.communication.Communication in project DataX by alibaba.

the class TaskGroupContainerTest method testStart.

@Test
public void testStart() throws InterruptedException {
    TaskGroupContainer taskGroupContainer = new TaskGroupContainer(this.configuration);
    taskGroupContainer.start();
    AbstractContainerCommunicator collector = taskGroupContainer.getContainerCommunicator();
    while (true) {
        State totalTaskState = collector.collectState();
        if (totalTaskState.isRunning()) {
            Thread.sleep(1000);
        } else {
            break;
        }
    }
    Communication totalTaskCommunication = collector.collect();
    List<String> messages = totalTaskCommunication.getMessage("bazhen-reader");
    Assert.assertTrue(!messages.isEmpty());
    messages = totalTaskCommunication.getMessage("bazhen-writer");
    Assert.assertTrue(!messages.isEmpty());
    messages = totalTaskCommunication.getMessage("bazhen");
    Assert.assertNull(messages);
    State state = totalTaskCommunication.getState();
    Assert.assertTrue("task finished", state.equals(State.SUCCEEDED));
}
Also used : TaskGroupContainer(com.alibaba.datax.core.taskgroup.TaskGroupContainer) State(com.alibaba.datax.dataxservice.face.domain.enums.State) AbstractContainerCommunicator(com.alibaba.datax.core.statistics.container.communicator.AbstractContainerCommunicator) Communication(com.alibaba.datax.core.statistics.communication.Communication) Test(org.junit.Test)

Example 28 with Communication

use of com.alibaba.datax.core.statistics.communication.Communication in project DataX by alibaba.

the class TaskGroupContainerTest method testFakeTransformer.

@Test
public void testFakeTransformer() {
    TransformerRegistry.registTransformer(new FakeSubstrTransformer());
    TransformerRegistry.registTransformer(new FakeReplaceTransformer());
    TransformerRegistry.registTransformer(new FakeGroovyTransformer());
    LoadUtil.bind(configurationFakeTransformer);
    this.configurationFakeTransformer.set("plugin.writer.fakewriter.class", FakeOneReader.class.getName());
    this.configurationFakeTransformer.set("plugin.writer.fakewriter.class", FakeLongTimeWriter.class.getName());
    this.configurationFakeTransformer.set(CoreConstant.DATAX_CORE_CONTAINER_TASKGROUP_CHANNEL, 1);
    Configuration jobContent = this.configurationFakeTransformer.getListConfiguration(CoreConstant.DATAX_JOB_CONTENT).get(0);
    List<Configuration> jobContents = new ArrayList<Configuration>();
    jobContents.add(jobContent);
    this.configurationFakeTransformer.set(CoreConstant.DATAX_JOB_CONTENT, jobContents);
    TaskGroupContainer taskGroupContainer = new TaskGroupContainer(this.configurationFakeTransformer);
    taskGroupContainer.start();
    Assert.assertTrue(State.SUCCEEDED == taskGroupContainer.getContainerCommunicator().collect().getState());
    Communication res = null;
    try {
        Method com = TaskGroupContainer.class.getDeclaredMethod("reportTaskGroupCommunication", Communication.class, int.class);
        com.setAccessible(true);
        res = (Communication) com.invoke(taskGroupContainer, new Communication(), 1);
        System.out.println("TaskGroup => " + CommunicationTool.Stringify.getSnapshot(res));
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertTrue(res != null);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TOTAL_READ_RECORDS).longValue(), 30);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_SUCCEED_RECORDS).longValue(), 10);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_FAILED_RECORDS).longValue(), 0);
    Assert.assertEquals(res.getLongCounter(CommunicationTool.TRANSFORMER_FILTER_RECORDS).longValue(), 10);
}
Also used : TaskGroupContainer(com.alibaba.datax.core.taskgroup.TaskGroupContainer) Configuration(com.alibaba.datax.common.util.Configuration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Communication(com.alibaba.datax.core.statistics.communication.Communication) Test(org.junit.Test)

Example 29 with Communication

use of com.alibaba.datax.core.statistics.communication.Communication in project DataX by alibaba.

the class ErrorRecordLimitTest method testCheckRecordLimit2.

@Test
public void testCheckRecordLimit2() throws Exception {
    ErrorRecordChecker errLimit = new ErrorRecordChecker(1L, 0.5);
    errLimit.checkRecordLimit(new Communication() {

        {
            this.setLongCounter(CommunicationTool.WRITE_FAILED_RECORDS, 1);
        }
    });
}
Also used : ErrorRecordChecker(com.alibaba.datax.core.util.ErrorRecordChecker) Communication(com.alibaba.datax.core.statistics.communication.Communication) Test(org.junit.Test)

Example 30 with Communication

use of com.alibaba.datax.core.statistics.communication.Communication in project DataX by alibaba.

the class ErrorRecordLimitTest method testCheckRecordLimit.

@Test(expected = DataXException.class)
public void testCheckRecordLimit() throws Exception {
    ErrorRecordChecker errLimit = new ErrorRecordChecker(0L, 0.5);
    errLimit.checkRecordLimit(new Communication() {

        {
            this.setLongCounter(CommunicationTool.WRITE_FAILED_RECORDS, 1);
        }
    });
}
Also used : ErrorRecordChecker(com.alibaba.datax.core.util.ErrorRecordChecker) Communication(com.alibaba.datax.core.statistics.communication.Communication) Test(org.junit.Test)

Aggregations

Communication (com.alibaba.datax.core.statistics.communication.Communication)35 Test (org.junit.Test)20 Configuration (com.alibaba.datax.common.util.Configuration)13 Method (java.lang.reflect.Method)6 LongColumn (com.alibaba.datax.common.element.LongColumn)5 Record (com.alibaba.datax.common.element.Record)5 Channel (com.alibaba.datax.core.transport.channel.Channel)5 MemoryChannel (com.alibaba.datax.core.transport.channel.memory.MemoryChannel)5 DefaultRecord (com.alibaba.datax.core.transport.record.DefaultRecord)5 ArrayList (java.util.ArrayList)5 TaskPluginCollector (com.alibaba.datax.common.plugin.TaskPluginCollector)4 TaskGroupContainer (com.alibaba.datax.core.taskgroup.TaskGroupContainer)4 ErrorRecordChecker (com.alibaba.datax.core.util.ErrorRecordChecker)4 JobContainer (com.alibaba.datax.core.job.JobContainer)3 AbstractContainerCommunicator (com.alibaba.datax.core.statistics.container.communicator.AbstractContainerCommunicator)3 VMInfo (com.alibaba.datax.common.statistics.VMInfo)2 LocalTGCommunicationManager (com.alibaba.datax.core.statistics.communication.LocalTGCommunicationManager)2 StandAloneJobContainerCommunicator (com.alibaba.datax.core.statistics.container.communicator.job.StandAloneJobContainerCommunicator)2 ProcessInnerReporter (com.alibaba.datax.core.statistics.container.report.ProcessInnerReporter)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2