Search in sources :

Example 1 with CountersDelegate

use of org.apache.tez.dag.app.MockDAGAppMaster.CountersDelegate in project tez by apache.

the class TestMockDAGAppMaster method testBasicCounters.

@Test(timeout = 10000)
public void testBasicCounters() throws Exception {
    TezConfiguration tezconf = new TezConfiguration(defaultConf);
    MockTezClient tezClient = new MockTezClient("testMockAM", tezconf, true, null, null, null, null, false, false);
    tezClient.start();
    final String vAName = "A";
    final String vBName = "B";
    final String procCounterName = "Proc";
    final String globalCounterName = "Global";
    DAG dag = DAG.create("testBasicCounters");
    Vertex vA = Vertex.create(vAName, ProcessorDescriptor.create("Proc.class"), 10);
    Vertex vB = Vertex.create(vBName, ProcessorDescriptor.create("Proc.class"), 1);
    dag.addVertex(vA).addVertex(vB).addEdge(Edge.create(vA, vB, EdgeProperty.create(DataMovementType.SCATTER_GATHER, DataSourceType.PERSISTED, SchedulingType.SEQUENTIAL, OutputDescriptor.create("Out"), InputDescriptor.create("In"))));
    TezCounters temp = new TezCounters();
    temp.findCounter(new String(globalCounterName), new String(globalCounterName)).increment(1);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutput out = new DataOutputStream(bos);
    temp.write(out);
    final byte[] payload = bos.toByteArray();
    MockDAGAppMaster mockApp = tezClient.getLocalClient().getMockApp();
    MockContainerLauncher mockLauncher = mockApp.getContainerLauncher();
    mockLauncher.startScheduling(false);
    mockApp.countersDelegate = new CountersDelegate() {

        @Override
        public TezCounters getCounters(TaskSpec taskSpec) {
            String vName = taskSpec.getVertexName();
            TezCounters counters = new TezCounters();
            final DataInputByteBuffer in = new DataInputByteBuffer();
            in.reset(ByteBuffer.wrap(payload));
            try {
                // this ensures that the serde code path is covered.
                // the internal merges of counters covers the constructor code path.
                counters.readFields(in);
            } catch (IOException e) {
                Assert.fail(e.getMessage());
            }
            counters.findCounter(vName, procCounterName).increment(1);
            for (OutputSpec output : taskSpec.getOutputs()) {
                counters.findCounter(vName, output.getDestinationVertexName()).increment(1);
            }
            for (InputSpec input : taskSpec.getInputs()) {
                counters.findCounter(vName, input.getSourceVertexName()).increment(1);
            }
            return counters;
        }
    };
    mockApp.doSleep = false;
    DAGClient dagClient = tezClient.submitDAG(dag);
    mockLauncher.waitTillContainersLaunched();
    DAGImpl dagImpl = (DAGImpl) mockApp.getContext().getCurrentDAG();
    mockLauncher.startScheduling(true);
    DAGStatus status = dagClient.waitForCompletion();
    Assert.assertEquals(DAGStatus.State.SUCCEEDED, status.getState());
    TezCounters counters = dagImpl.getAllCounters();
    String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
    if (SystemUtils.IS_OS_LINUX) {
        Assert.assertTrue(counters.findCounter(DAGCounter.AM_CPU_MILLISECONDS).getValue() > 0);
    }
    // verify processor counters
    Assert.assertEquals(10, counters.findCounter(vAName, procCounterName).getValue());
    Assert.assertEquals(1, counters.findCounter(vBName, procCounterName).getValue());
    // verify edge counters
    Assert.assertEquals(10, counters.findCounter(vAName, vBName).getValue());
    Assert.assertEquals(1, counters.findCounter(vBName, vAName).getValue());
    // verify global counters
    Assert.assertEquals(11, counters.findCounter(globalCounterName, globalCounterName).getValue());
    VertexImpl vAImpl = (VertexImpl) dagImpl.getVertex(vAName);
    VertexImpl vBImpl = (VertexImpl) dagImpl.getVertex(vBName);
    TezCounters vACounters = vAImpl.getAllCounters();
    TezCounters vBCounters = vBImpl.getAllCounters();
    String vACounterName = vACounters.findCounter(globalCounterName, globalCounterName).getName();
    String vBCounterName = vBCounters.findCounter(globalCounterName, globalCounterName).getName();
    if (vACounterName != vBCounterName) {
        Assert.fail("String counter name objects dont match despite interning.");
    }
    CounterGroup vaGroup = vACounters.getGroup(globalCounterName);
    String vaGrouName = vaGroup.getName();
    CounterGroup vBGroup = vBCounters.getGroup(globalCounterName);
    String vBGrouName = vBGroup.getName();
    if (vaGrouName != vBGrouName) {
        Assert.fail("String group name objects dont match despite interning.");
    }
    tezClient.stop();
}
Also used : Vertex(org.apache.tez.dag.api.Vertex) DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) DataInputByteBuffer(org.apache.hadoop.io.DataInputByteBuffer) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) CounterGroup(org.apache.tez.common.counters.CounterGroup) CountersDelegate(org.apache.tez.dag.app.MockDAGAppMaster.CountersDelegate) InputSpec(org.apache.tez.runtime.api.impl.InputSpec) DAG(org.apache.tez.dag.api.DAG) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MockContainerLauncher(org.apache.tez.dag.app.MockDAGAppMaster.MockContainerLauncher) TezCounters(org.apache.tez.common.counters.TezCounters) DAGImpl(org.apache.tez.dag.app.dag.impl.DAGImpl) DAGClient(org.apache.tez.dag.api.client.DAGClient) DAGStatus(org.apache.tez.dag.api.client.DAGStatus) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) OutputSpec(org.apache.tez.runtime.api.impl.OutputSpec) VertexImpl(org.apache.tez.dag.app.dag.impl.VertexImpl) Test(org.junit.Test)

Example 2 with CountersDelegate

use of org.apache.tez.dag.app.MockDAGAppMaster.CountersDelegate in project tez by apache.

the class TestMockDAGAppMaster method testBasicCounterMemory.

@Ignore
@Test(timeout = 60000)
public void testBasicCounterMemory() throws Exception {
    Logger.getRootLogger().setLevel(Level.WARN);
    TezConfiguration tezconf = new TezConfiguration(defaultConf);
    MockTezClient tezClient = new MockTezClient("testMockAM", tezconf, true, null, null, null, null, false, false);
    tezClient.start();
    final String vAName = "A";
    DAG dag = DAG.create("testBasicCounterMemory");
    Vertex vA = Vertex.create(vAName, ProcessorDescriptor.create("Proc.class"), 10000);
    dag.addVertex(vA);
    MockDAGAppMaster mockApp = tezClient.getLocalClient().getMockApp();
    MockContainerLauncher mockLauncher = mockApp.getContainerLauncher();
    mockLauncher.startScheduling(false);
    mockApp.countersDelegate = new CountersDelegate() {

        @Override
        public TezCounters getCounters(TaskSpec taskSpec) {
            TezCounters counters = new TezCounters();
            final String longName = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
            final String shortName = "abcdefghijklmnopqrstuvwxyz";
            for (int i = 0; i < 6; ++i) {
                for (int j = 0; j < 15; ++j) {
                    counters.findCounter((i + longName), (i + (shortName))).increment(1);
                }
            }
            return counters;
        }
    };
    mockApp.doSleep = false;
    DAGClient dagClient = tezClient.submitDAG(dag);
    mockLauncher.waitTillContainersLaunched();
    DAGImpl dagImpl = (DAGImpl) mockApp.getContext().getCurrentDAG();
    mockLauncher.startScheduling(true);
    DAGStatus status = dagClient.waitForCompletion();
    Assert.assertEquals(DAGStatus.State.SUCCEEDED, status.getState());
    TezCounters counters = dagImpl.getAllCounters();
    Assert.assertNotNull(counters);
    checkMemory(dag.getName(), mockApp);
    tezClient.stop();
}
Also used : Vertex(org.apache.tez.dag.api.Vertex) TaskSpec(org.apache.tez.runtime.api.impl.TaskSpec) CountersDelegate(org.apache.tez.dag.app.MockDAGAppMaster.CountersDelegate) DAG(org.apache.tez.dag.api.DAG) MockContainerLauncher(org.apache.tez.dag.app.MockDAGAppMaster.MockContainerLauncher) TezCounters(org.apache.tez.common.counters.TezCounters) DAGImpl(org.apache.tez.dag.app.dag.impl.DAGImpl) DAGClient(org.apache.tez.dag.api.client.DAGClient) DAGStatus(org.apache.tez.dag.api.client.DAGStatus) TezConfiguration(org.apache.tez.dag.api.TezConfiguration) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TezCounters (org.apache.tez.common.counters.TezCounters)2 DAG (org.apache.tez.dag.api.DAG)2 TezConfiguration (org.apache.tez.dag.api.TezConfiguration)2 Vertex (org.apache.tez.dag.api.Vertex)2 DAGClient (org.apache.tez.dag.api.client.DAGClient)2 DAGStatus (org.apache.tez.dag.api.client.DAGStatus)2 CountersDelegate (org.apache.tez.dag.app.MockDAGAppMaster.CountersDelegate)2 MockContainerLauncher (org.apache.tez.dag.app.MockDAGAppMaster.MockContainerLauncher)2 DAGImpl (org.apache.tez.dag.app.dag.impl.DAGImpl)2 TaskSpec (org.apache.tez.runtime.api.impl.TaskSpec)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutput (java.io.DataOutput)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 DataInputByteBuffer (org.apache.hadoop.io.DataInputByteBuffer)1 CounterGroup (org.apache.tez.common.counters.CounterGroup)1 VertexImpl (org.apache.tez.dag.app.dag.impl.VertexImpl)1 InputSpec (org.apache.tez.runtime.api.impl.InputSpec)1 OutputSpec (org.apache.tez.runtime.api.impl.OutputSpec)1