Search in sources :

Example 86 with NonStrictExpectations

use of mockit.NonStrictExpectations in project drill by apache.

the class PhysicalOpUnitTestBase method mockOpContext.

protected void mockOpContext(long initReservation, long maxAllocation) throws Exception {
    final BufferAllocator allocator = this.allocator.newChildAllocator("allocator_for_operator_test", initReservation, maxAllocation);
    new NonStrictExpectations() {

        {
            opContext.getStats();
            result = opStats;
            opContext.getAllocator();
            result = allocator;
            fragContext.newOperatorContext(withAny(popConf));
            result = opContext;
        }
    };
}
Also used : NonStrictExpectations(mockit.NonStrictExpectations) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator)

Example 87 with NonStrictExpectations

use of mockit.NonStrictExpectations in project pentaho-platform by pentaho.

the class ChartHelperTest method deprecateWarningTest.

@Test
@SuppressWarnings("deprecation")
public void deprecateWarningTest() {
    final Class<?> deprecatedClass = ChartHelper.class;
    final Method[] methods = deprecatedClass.getDeclaredMethods();
    final List<Method> notPrivateMethods = new ArrayList<Method>(methods.length);
    for (Method m : methods) {
        if (!Modifier.isPrivate(m.getModifiers())) {
            notPrivateMethods.add(m);
        }
    }
    new NonStrictExpectations(Logger.class) {

        {
            Logger.warn(deprecatedClass, withSubstring("deprecated"));
            result = new Exception();
            times = notPrivateMethods.size();
        }
    };
    for (Method m : notPrivateMethods) {
        try {
            Deencapsulation.invoke(deprecatedClass, m.getName(), (Object[]) m.getParameterTypes());
            fail();
        } catch (Exception e) {
            System.out.println(MessageFormat.format("Method {0}.{1}(..) sucessfully deprecated", deprecatedClass.getCanonicalName(), m.getName()));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Example 88 with NonStrictExpectations

use of mockit.NonStrictExpectations in project drill by axbaretto.

the class TestOptiqPlans method doLogicalTest.

private SimpleRootExec doLogicalTest(final BootStrapContext context, UserClientConnection connection, String file, ClusterCoordinator coord, DataConnectionCreator com, Controller controller, WorkEventBus workBus) throws Exception {
    new NonStrictExpectations() {

        {
            context.getMetrics();
            result = new MetricRegistry();
            context.getAllocator();
            result = RootAllocatorFactory.newRoot(config);
            context.getConfig();
            result = config;
        }
    };
    final RemoteServiceSet lss = RemoteServiceSet.getLocalServiceSet();
    final DrillbitContext bitContext = new DrillbitContext(DrillbitEndpoint.getDefaultInstance(), context, coord, controller, com, workBus, new LocalPersistentStoreProvider(config));
    final QueryContext qc = new QueryContext(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build(), bitContext, QueryId.getDefaultInstance());
    final PhysicalPlanReader reader = bitContext.getPlanReader();
    final LogicalPlan plan = reader.readLogicalPlan(Files.toString(DrillFileUtils.getResourceAsFile(file), Charsets.UTF_8));
    final PhysicalPlan pp = new BasicOptimizer(qc, connection).optimize(new BasicOptimizer.BasicOptimizationContext(qc), plan);
    final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(config);
    final FragmentContext fctxt = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(fctxt, (FragmentRoot) pp.getSortedOperators(false).iterator().next()));
    return exec;
}
Also used : DrillbitContext(org.apache.drill.exec.server.DrillbitContext) BasicOptimizer(org.apache.drill.exec.opt.BasicOptimizer) PhysicalPlan(org.apache.drill.exec.physical.PhysicalPlan) FragmentContext(org.apache.drill.exec.ops.FragmentContext) LocalPersistentStoreProvider(org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider) PhysicalPlanReader(org.apache.drill.exec.planner.PhysicalPlanReader) MetricRegistry(com.codahale.metrics.MetricRegistry) FragmentRoot(org.apache.drill.exec.physical.base.FragmentRoot) QueryContext(org.apache.drill.exec.ops.QueryContext) RemoteServiceSet(org.apache.drill.exec.server.RemoteServiceSet) LogicalPlan(org.apache.drill.common.logical.LogicalPlan) NonStrictExpectations(mockit.NonStrictExpectations) FunctionImplementationRegistry(org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)

Example 89 with NonStrictExpectations

use of mockit.NonStrictExpectations 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)

Example 90 with NonStrictExpectations

use of mockit.NonStrictExpectations in project azure-iot-sdk-java by Azure.

the class DeviceMethodTest method invokeThrowOnCreateMethodResponseFailed.

/* Tests_SRS_DEVICEMETHOD_21_013: [The invoke shall deserialize the payload using the `serializer.MethodParser`.] */
@SuppressWarnings("EmptyMethod")
@Test(expected = IllegalArgumentException.class)
public void invokeThrowOnCreateMethodResponseFailed(@Mocked final DeviceOperations request, @Mocked final IotHubServiceSasToken iotHubServiceSasToken) throws Exception {
    // arrange
    DeviceMethod testMethod = DeviceMethod.createFromConnectionString(STANDARD_CONNECTIONSTRING);
    new NonStrictExpectations() {

        {
            IotHubConnectionString.getUrlMethod(anyString, STANDARD_DEVICEID);
            result = STANDARD_URL;
        }
    };
    new MockUp<MethodParser>() {

        @Mock
        void $init(String name, Long responseTimeoutInSeconds, Long connectTimeoutInSeconds, Object payload) throws IllegalArgumentException {
        }

        @Mock
        void $init() {
        }

        @Mock
        String toJson() {
            return STANDARD_JSON;
        }

        @Mock
        void fromJson(String json) {
            throw new IllegalArgumentException();
        }
    };
    // act
    testMethod.invoke(STANDARD_DEVICEID, STANDARD_METHODNAME, STANDARD_TIMEOUT_SECONDS, STANDARD_TIMEOUT_SECONDS, STANDARD_PAYLOAD_MAP);
}
Also used : MockUp(mockit.MockUp) IotHubConnectionString(com.microsoft.azure.sdk.iot.service.IotHubConnectionString) DeviceMethod(com.microsoft.azure.sdk.iot.service.devicetwin.DeviceMethod) NonStrictExpectations(mockit.NonStrictExpectations) Test(org.junit.Test)

Aggregations

NonStrictExpectations (mockit.NonStrictExpectations)476 Test (org.junit.Test)470 Verifications (mockit.Verifications)154 IotHubConnectionString (com.microsoft.azure.sdk.iot.service.IotHubConnectionString)77 IOException (java.io.IOException)64 HttpConnection (com.microsoft.azure.sdk.iot.service.transport.http.HttpConnection)51 HttpMethod (com.microsoft.azure.sdk.iot.service.transport.http.HttpMethod)51 DeviceTwin (com.microsoft.azure.sdk.iot.service.devicetwin.DeviceTwin)47 MessageProperty (com.microsoft.azure.sdk.iot.device.MessageProperty)32 HttpsSingleMessage (com.microsoft.azure.sdk.iot.device.transport.https.HttpsSingleMessage)31 HttpConnection (com.microsoft.azure.sdk.iot.deps.transport.http.HttpConnection)26 HttpMethod (com.microsoft.azure.sdk.iot.deps.transport.http.HttpMethod)26 HttpsConnection (com.microsoft.azure.sdk.iot.device.transport.https.HttpsConnection)26 HttpsMethod (com.microsoft.azure.sdk.iot.device.transport.https.HttpsMethod)26 HashMap (java.util.HashMap)26 JobClient (com.microsoft.azure.sdk.iot.service.jobs.JobClient)25 IotHubConnectionString (com.microsoft.azure.sdk.iot.device.IotHubConnectionString)17 Date (java.util.Date)16 HashSet (java.util.HashSet)16 Query (com.microsoft.azure.sdk.iot.service.devicetwin.Query)15