天天看點

dremio 測試類SabotNode簡單說明

實際上我以前簡單說明過dremio 的一些測試類以及如何進行測試一般我們使用BaseTestQuery 就可以了

實際上對于測試dremio 包裝了一個SabotNode 類,提供了不帶ui 的測試架構能力(server 引擎能力)

SabotNode 提供的能力

SabotNode 是一個dremio 運作依賴的基本元件的包裝,了解dremioSabotNode 依賴的元件之後可以更好的學習 dremio

dremio 測試類SabotNode簡單說明

基本測試使用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 測試類SabotNode簡單說明

測試參考使用

實際上官方測試案例代碼還是比較全的,可以了解測試的使用,同時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();
    }
}
      

說明

參考資料