use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestPauseInjection method timedPauseOnSpecificBit.
@Test
public void timedPauseOnSpecificBit() {
final RemoteServiceSet remoteServiceSet = RemoteServiceSet.getLocalServiceSet();
final ZookeeperHelper zkHelper = new ZookeeperHelper();
zkHelper.startZookeeper(1);
final long pauseDuration = 2000L;
final long expectedDuration = pauseDuration;
try {
// Creating two drillbits
final Drillbit drillbit1, drillbit2;
final DrillConfig drillConfig = zkHelper.getConfig();
try {
drillbit1 = Drillbit.start(drillConfig, remoteServiceSet);
drillbit2 = Drillbit.start(drillConfig, remoteServiceSet);
} catch (final DrillbitStartupException e) {
throw new RuntimeException("Failed to start two drillbits.", e);
}
final DrillbitContext drillbitContext1 = drillbit1.getContext();
final DrillbitContext drillbitContext2 = drillbit2.getContext();
final UserSession session = UserSession.Builder.newBuilder().withCredentials(UserCredentials.newBuilder().setUserName("foo").build()).withUserProperties(UserProperties.getDefaultInstance()).withOptionManager(drillbitContext1.getOptionManager()).build();
final DrillbitEndpoint drillbitEndpoint1 = drillbitContext1.getEndpoint();
final String controls = Controls.newBuilder().addTimedPauseOnBit(DummyClass.class, DummyClass.PAUSES, drillbitEndpoint1, 0, pauseDuration).build();
ControlsInjectionUtil.setControls(session, controls);
{
final ExtendedLatch trigger = new ExtendedLatch(1);
final Pointer<Exception> ex = new Pointer<>();
final QueryContext queryContext = new QueryContext(session, drillbitContext1, QueryId.getDefaultInstance());
// test that the pause happens
final DummyClass dummyClass = new DummyClass(queryContext, trigger);
final long actualDuration = dummyClass.pauses();
assertTrue(String.format("Test should stop for at least %d milliseconds.", expectedDuration), expectedDuration <= actualDuration);
assertNull("No exception should be thrown.", ex.value);
try {
queryContext.close();
} catch (final Exception e) {
fail("Failed to close query context: " + e);
}
}
{
final ExtendedLatch trigger = new ExtendedLatch(1);
final QueryContext queryContext = new QueryContext(session, drillbitContext2, QueryId.getDefaultInstance());
// if the resume did not happen, the test would hang
final DummyClass dummyClass = new DummyClass(queryContext, trigger);
dummyClass.pauses();
try {
queryContext.close();
} catch (final Exception e) {
fail("Failed to close query context: " + e);
}
}
} finally {
zkHelper.stopZookeeper();
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestGracefulShutdown method testDrillbitWithSamePortContainsShutdownThread.
// DRILL-6912
@Test
public void testDrillbitWithSamePortContainsShutdownThread() throws Exception {
ClusterFixtureBuilder fixtureBuilder = ClusterFixture.builder(dirTestWatcher).withLocalZk().configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true).configProperty(ExecConstants.INITIAL_USER_PORT, QueryTestUtil.getFreePortNumber(31170, 300)).configProperty(ExecConstants.INITIAL_BIT_PORT, QueryTestUtil.getFreePortNumber(31180, 300));
try (ClusterFixture fixture = fixtureBuilder.build();
Drillbit drillbitWithSamePort = new Drillbit(fixture.config(), fixtureBuilder.configBuilder().getDefinitions(), fixture.serviceSet())) {
// Assert preconditions :
// 1. First drillbit instance should be started normally
// 2. Second instance startup should fail, because ports are occupied by the first one
assertNotNull("First drillbit instance should be initialized", fixture.drillbit());
try {
drillbitWithSamePort.run();
fail("Invocation of 'drillbitWithSamePort.run()' should throw UserException");
} catch (UserException e) {
assertThat(e.getMessage(), containsString("RESOURCE ERROR: Drillbit could not bind to port"));
// Ensure that drillbit with failed startup may be safely closed
assertNotNull("Drillbit.gracefulShutdownThread shouldn't be null, otherwise close() may throw NPE (if so, check suppressed exception).", drillbitWithSamePort.getGracefulShutdownThread());
}
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestGracefulShutdown method testOnlineEndPoints.
/*
Start multiple drillbits and then shutdown a drillbit. Query the online
endpoints and check if the drillbit still exists.
*/
@Test
public void testOnlineEndPoints() throws Exception {
String[] drillbits = { "db1", "db2", "db3" };
ClusterFixtureBuilder builder = builderWithEnabledPortHunting().withLocalZk().withBits(drillbits);
try (ClusterFixture cluster = builder.build()) {
Drillbit drillbit = cluster.drillbit("db2");
int zkRefresh = drillbit.getContext().getConfig().getInt(ExecConstants.ZK_REFRESH);
DrillbitEndpoint drillbitEndpoint = drillbit.getRegistrationHandle().getEndPoint();
cluster.closeDrillbit("db2");
while (true) {
Collection<DrillbitEndpoint> drillbitEndpoints = cluster.drillbit().getContext().getClusterCoordinator().getOnlineEndPoints();
if (!drillbitEndpoints.contains(drillbitEndpoint)) {
// Success
return;
}
Thread.sleep(zkRefresh);
}
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestHashJoin method hjWithExchange1.
@Test
public void hjWithExchange1() throws Throwable {
// Another test for hash join with exchanges
try (final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
final Drillbit bit = new Drillbit(CONFIG, serviceSet);
final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
// run query.
bit.run();
client.connect();
final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile("/join/hj_exchanges1.json"), Charsets.UTF_8).read());
int count = 0;
for (final QueryDataBatch b : results) {
if (b.getHeader().getRowCount() != 0) {
count += b.getHeader().getRowCount();
}
b.release();
}
assertEquals(272, count);
}
}
use of org.apache.drill.exec.server.Drillbit in project drill by apache.
the class TestHashJoin method testHashJoinExprInCondition.
@Test
public void testHashJoinExprInCondition() throws Exception {
final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
try (final Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
final DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {
bit1.run();
client.connect();
final List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL, Files.asCharSource(DrillFileUtils.getResourceAsFile("/join/hashJoinExpr.json"), Charsets.UTF_8).read());
int count = 0;
for (final QueryDataBatch b : results) {
if (b.getHeader().getRowCount() != 0) {
count += b.getHeader().getRowCount();
}
b.release();
}
assertEquals(10, count);
}
}
Aggregations