-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6eeb933
commit 435ee17
Showing
5 changed files
with
191 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockBreakageStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.drill.exec.store.mock; | ||
|
||
import org.apache.calcite.schema.SchemaPlus; | ||
import org.apache.drill.exec.server.DrillbitContext; | ||
import org.apache.drill.exec.store.SchemaConfig; | ||
|
||
import java.io.IOException; | ||
|
||
public class MockBreakageStorage extends MockStorageEngine { | ||
|
||
boolean breakRegister; | ||
public MockBreakageStorage(MockStorageEngineConfig configuration, DrillbitContext context, String name) { | ||
super(configuration, context, name); | ||
breakRegister = false; | ||
} | ||
|
||
public void setBreakRegister(boolean breakRegister) { | ||
this.breakRegister = breakRegister; | ||
} | ||
|
||
@Override | ||
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException { | ||
if (breakRegister) { | ||
throw new IOException("mock breakRegister!"); | ||
} | ||
super.registerSchemas(schemaConfig, parent); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
exec/java-exec/src/test/java/org/apache/drill/exec/physical/impl/TestSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.drill.exec.physical.impl; | ||
|
||
import org.apache.drill.test.ClientFixture; | ||
import org.apache.drill.test.ClusterFixture; | ||
import org.apache.drill.test.ClusterMockStorageFixture; | ||
import org.apache.drill.test.DrillTest; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TestSchema extends DrillTest { | ||
|
||
private static ClusterMockStorageFixture cluster; | ||
private static ClientFixture client; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
cluster = ClusterFixture.builder().buildCustomMockStorage(); | ||
boolean breakRegisterSchema = true; | ||
cluster.insertMockStorage("mock_broken", breakRegisterSchema); | ||
cluster.insertMockStorage("mock_good", !breakRegisterSchema); | ||
client = cluster.clientFixture(); | ||
} | ||
|
||
@Test | ||
public void testQueryBrokenStorage() { | ||
String sql = "SELECT id_i, name_s10 FROM `mock_broken`.`employees_5`"; | ||
try { | ||
client.queryBuilder().sql(sql).printCsv(); | ||
} catch (Exception ex) { | ||
assertTrue(ex.getMessage().contains("VALIDATION ERROR: Schema")); | ||
} | ||
} | ||
|
||
@Test | ||
public void testQueryGoodStorage() { | ||
String sql = "SELECT id_i, name_s10 FROM `mock_good`.`employees_5`"; | ||
client.queryBuilder().sql(sql).printCsv(); | ||
} | ||
|
||
@Test | ||
public void testQueryGoodStorageWithDefaultSchema() throws Exception { | ||
String use_dfs = "use dfs.tmp"; | ||
client.queryBuilder().sql(use_dfs).run(); | ||
String sql = "SELECT id_i, name_s10 FROM `mock_good`.`employees_5`"; | ||
client.queryBuilder().sql(sql).printCsv(); | ||
} | ||
|
||
@Test | ||
public void testUseBrokenStorage() throws Exception { | ||
try { | ||
String use_dfs = "use mock_broken"; | ||
client.queryBuilder().sql(use_dfs).run(); | ||
} catch(Exception ex) { | ||
assertTrue(ex.getMessage().contains("VALIDATION ERROR: Schema")); | ||
} | ||
} | ||
|
||
@AfterClass | ||
public static void close() throws Exception { | ||
} | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
exec/java-exec/src/test/java/org/apache/drill/test/ClusterMockStorageFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.drill.test; | ||
|
||
import org.apache.drill.exec.server.Drillbit; | ||
import org.apache.drill.exec.store.StoragePluginRegistry; | ||
import org.apache.drill.exec.store.StoragePluginRegistryImpl; | ||
import org.apache.drill.exec.store.mock.MockBreakageStorage; | ||
import org.apache.drill.exec.store.mock.MockStorageEngineConfig; | ||
|
||
public class ClusterMockStorageFixture extends ClusterFixture { | ||
ClusterMockStorageFixture(FixtureBuilder builder) { | ||
super(builder); | ||
|
||
} | ||
|
||
/** | ||
* This should be called after bits are started | ||
* @param name nthe mock storage name we are going to create | ||
*/ | ||
public void insertMockStorage(String name, boolean breakRegisterSchema) { | ||
for (Drillbit bit : drillbits()) { | ||
|
||
// Bit name and registration. | ||
final StoragePluginRegistry pluginRegistry = bit.getContext().getStorage(); | ||
MockStorageEngineConfig config = MockStorageEngineConfig.INSTANCE; | ||
@SuppressWarnings("resource") | ||
MockBreakageStorage plugin = new MockBreakageStorage( | ||
MockStorageEngineConfig.INSTANCE, bit.getContext(), name); | ||
((StoragePluginRegistryImpl) pluginRegistry).definePlugin(name, config, plugin); | ||
|
||
plugin.setBreakRegister(breakRegisterSchema); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters