實際上我以前簡單說明過dremio 的一些測試類以及如何進行測試一般我們使用BaseTestQuery 就可以了
實際上對于測試dremio 包裝了一個SabotNode 類,提供了不帶ui 的測試架構能力(server 引擎能力)
SabotNode 提供的能力
SabotNode 是一個dremio 運作依賴的基本元件的包裝,了解dremioSabotNode 依賴的元件之後可以更好的學習 dremio
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5iN0QTM2AzNjNTOzgjZjJTNzYzX5MzN1ADMyIzLcBTMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.png)
基本測試使用BaseTestQuery 類
- 測試類
@BeforeClass
public static void setupDefaultTestCluster() throws Exception {
config = SabotConfig.create(TEST_CONFIGURATIONS);
Module module = Optional.ofNullable(SABOT_NODE_RULE.module)
.map(m -> Modules.combine(m, getDefaultModule())).orElse(getDefaultModule());
SABOT_NODE_RULE.register(module);
openClient();
localFs = HadoopFileSystem.getLocal(new Configuration());
// turns on the verbose errors in tests
// sever side stacktraces are added to the message before sending back to the client
setSessionOption(ExecConstants.ENABLE_VERBOSE_ERRORS_KEY, "true");
}
openClient 建立SabotNode
protected static void openClient() throws Exception {
clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
dfsTestTmpSchemaLocation = TestUtilities.createTempDir();
nodes = new SabotNode[nodeCount];
for(int i = 0; i < nodeCount; i++) {
// first node has all roles, and all others are only executors
nodes[i] = SABOT_NODE_RULE.newSabotNode(new SabotProviderConfig(i == 0));
nodes[i].run();
if(i == 0) {
TestUtilities.addDefaultTestPlugins(nodes[i].getContext().getCatalogService(), dfsTestTmpSchemaLocation, true);
}
}
client = QueryTestUtil.createClient(config, clusterCoordinator, MAX_WIDTH_PER_NODE, defaultProperties);
// turn off re-attempts, this needs to be set at the system level as many unit test will
// reset the user session by restarting the client
setEnableReAttempts(false);
}
SabotModule 子產品能力
SabotModule 屬于一個guice 的标準子產品,包含了依賴的子產品,可以了解依賴的元件
測試參考使用
實際上官方測試案例代碼還是比較全的,可以了解測試的使用,同時dremio 對于測試包也釋出了maven 私服可以友善使用
比如簡單source 擴充的測試(執行sql 操作的)=
public class MyPluginTest extends BaseTestQuery {
private CrateConf crateConf;
@Before
public void initSource(){
getSabotContext().getOptionManager().setOption(OptionValue.createLong(OptionValue.OptionType.SYSTEM, ExecConstants.ELASTIC_ACTION_RETRIES, 3));
SourceConfig sc = new SourceConfig();
sc.setName("cratedb");
crateConf = new CrateConf();
crateConf.host="127.0.0.1";
crateConf.port=5433;
crateConf.username="crate";
sc.setConnectionConf(crateConf);
sc.setMetadataPolicy(CatalogService.DEFAULT_METADATA_POLICY);
getSabotContext().getCatalogService().createSourceIfMissingWithThrow(sc);
}
@Test
public void test() throws Exception {
String query = "select * from cratedb.doc.demoapp";
TestResult testResult= testBuilder()
.sqlQuery(query)
.unOrdered()
.baselineColumns("id", "name")
.baselineValues(null, null)
.go();
}
}