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;
}
};
}
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()));
}
}
}
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;
}
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);
}
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);
}
Aggregations