Search in sources :

Example 1 with DataConnectionManager

use of org.apache.drill.exec.rpc.data.DataConnectionManager in project drill by axbaretto.

the class TestBitRpc method testConnectionBackpressure.

@Test
public void testConnectionBackpressure(@Injectable WorkerBee bee, @Injectable final WorkEventBus workBus) throws Exception {
    DrillConfig config1 = DrillConfig.create();
    final BootStrapContext c = new BootStrapContext(config1, ClassPathScanner.fromPrescan(config1));
    DrillConfig config2 = DrillConfig.create();
    BootStrapContext c2 = new BootStrapContext(config2, ClassPathScanner.fromPrescan(config2));
    final FragmentContext fcon = new MockUp<FragmentContext>() {

        BufferAllocator getAllocator() {
            return c.getAllocator();
        }
    }.getMockInstance();
    final FragmentManager fman = new MockUp<FragmentManager>() {

        int v = 0;

        @Mock
        boolean handle(IncomingDataBatch batch) throws FragmentSetupException, IOException {
            try {
                v++;
                if (v % 10 == 0) {
                    System.out.println("sleeping.");
                    Thread.sleep(3000);
                }
            } catch (InterruptedException e) {
            }
            RawFragmentBatch rfb = batch.newRawFragmentBatch(c.getAllocator());
            rfb.sendOk();
            rfb.release();
            return true;
        }

        public FragmentContext getFragmentContext() {
            return fcon;
        }
    }.getMockInstance();
    new NonStrictExpectations() {

        {
            workBus.getFragmentManagerIfExists((FragmentHandle) any);
            result = fman;
            workBus.getFragmentManager((FragmentHandle) any);
            result = fman;
        }
    };
    int port = 1234;
    DataServer server = new DataServer(c, c.getAllocator(), workBus, null);
    port = server.bind(port, true);
    DrillbitEndpoint ep = DrillbitEndpoint.newBuilder().setAddress("localhost").setDataPort(port).build();
    DataConnectionManager manager = new DataConnectionManager(ep, c2);
    DataTunnel tunnel = new DataTunnel(manager);
    AtomicLong max = new AtomicLong(0);
    for (int i = 0; i < 40; i++) {
        long t1 = System.currentTimeMillis();
        tunnel.sendRecordBatch(new TimingOutcome(max), new FragmentWritableBatch(false, QueryId.getDefaultInstance(), 1, 1, 1, 1, getRandomBatch(c.getAllocator(), 5000)));
        System.out.println(System.currentTimeMillis() - t1);
    // System.out.println("sent.");
    }
    System.out.println(String.format("Max time: %d", max.get()));
    assertTrue(max.get() > 2700);
    Thread.sleep(5000);
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) DataTunnel(org.apache.drill.exec.rpc.data.DataTunnel) FragmentContext(org.apache.drill.exec.ops.FragmentContext) FragmentWritableBatch(org.apache.drill.exec.record.FragmentWritableBatch) IncomingDataBatch(org.apache.drill.exec.rpc.data.IncomingDataBatch) FragmentSetupException(org.apache.drill.exec.exception.FragmentSetupException) IOException(java.io.IOException) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) Mock(mockit.Mock) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) DataConnectionManager(org.apache.drill.exec.rpc.data.DataConnectionManager) FragmentManager(org.apache.drill.exec.work.fragment.FragmentManager) AtomicLong(java.util.concurrent.atomic.AtomicLong) DrillbitEndpoint(org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint) DrillConfig(org.apache.drill.common.config.DrillConfig) DataServer(org.apache.drill.exec.rpc.data.DataServer) NonStrictExpectations(mockit.NonStrictExpectations) ExecTest(org.apache.drill.exec.ExecTest) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Mock (mockit.Mock)1 NonStrictExpectations (mockit.NonStrictExpectations)1 DrillConfig (org.apache.drill.common.config.DrillConfig)1 ExecTest (org.apache.drill.exec.ExecTest)1 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)1 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)1 FragmentContext (org.apache.drill.exec.ops.FragmentContext)1 DrillbitEndpoint (org.apache.drill.exec.proto.CoordinationProtos.DrillbitEndpoint)1 FragmentWritableBatch (org.apache.drill.exec.record.FragmentWritableBatch)1 RawFragmentBatch (org.apache.drill.exec.record.RawFragmentBatch)1 DataConnectionManager (org.apache.drill.exec.rpc.data.DataConnectionManager)1 DataServer (org.apache.drill.exec.rpc.data.DataServer)1 DataTunnel (org.apache.drill.exec.rpc.data.DataTunnel)1 IncomingDataBatch (org.apache.drill.exec.rpc.data.IncomingDataBatch)1 FragmentManager (org.apache.drill.exec.work.fragment.FragmentManager)1 Test (org.junit.Test)1