コード例 #1
0
    public Object call() {
      final ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
      ScriptEngine e = scriptEngineManager.getEngineByName("javascript");
      if (map != null) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
          e.put(entry.getKey(), entry.getValue());
        }
      }
      e.put("hazelcast", hazelcastInstance);
      try {
        // For new JavaScript engine called Nashorn we need the compatibility script
        if (e.getFactory().getEngineName().toLowerCase().contains("nashorn")) {
          e.eval("load('nashorn:mozilla_compat.js');");
        }

        e.eval("importPackage(java.lang);");
        e.eval("importPackage(java.util);");
        e.eval("importPackage(com.hazelcast.core);");
        e.eval("importPackage(com.hazelcast.config);");
        e.eval("importPackage(java.util.concurrent);");
        e.eval("importPackage(org.junit);");

        return e.eval(script);
      } catch (ScriptException e1) {
        throw new RuntimeException(e1);
      }
    }
コード例 #2
0
ファイル: TestBase.java プロジェクト: kakao/hbase-tools
 protected HServerLoad.RegionLoad getRegionLoad(HRegionInfo regionInfo, ServerName serverName)
     throws IOException {
   HServerLoad serverLoad = admin.getClusterStatus().getLoad(serverName);
   Map<byte[], HServerLoad.RegionLoad> regionsLoad = serverLoad.getRegionsLoad();
   for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : regionsLoad.entrySet()) {
     if (Arrays.equals(entry.getKey(), regionInfo.getRegionName())) {
       return entry.getValue();
     }
   }
   return null;
 }
コード例 #3
0
ファイル: TestBase.java プロジェクト: kakao/hbase-tools
  protected void waitForMoving(HRegionInfo hRegionInfo, ServerName serverName) throws Exception {
    Map<byte[], HServerLoad.RegionLoad> regionsLoad = null;
    for (int i = 0; i < MAX_WAIT_ITERATION; i++) {
      HServerLoad load = admin.getClusterStatus().getLoad(serverName);
      regionsLoad = load.getRegionsLoad();
      for (byte[] regionName : regionsLoad.keySet()) {
        if (Arrays.equals(regionName, hRegionInfo.getRegionName())) return;
      }
      admin.move(hRegionInfo.getEncodedNameAsBytes(), serverName.getServerName().getBytes());
      Thread.sleep(WAIT_INTERVAL);
    }

    System.out.println("hRegionInfo = " + Bytes.toString(hRegionInfo.getRegionName()));
    for (Map.Entry<byte[], HServerLoad.RegionLoad> entry : regionsLoad.entrySet()) {
      System.out.println(
          "regionsLoad = " + Bytes.toString(entry.getKey()) + " - " + entry.getValue());
    }

    Assert.fail(Util.getMethodName() + " failed");
  }
コード例 #4
0
ファイル: TestBase.java プロジェクト: kakao/hbase-tools
  protected void waitForSplitting(String tableName, int regionCount)
      throws IOException, InterruptedException {
    int regionCountActual = 0;
    for (int i = 0; i < MAX_WAIT_ITERATION; i++) {
      try (HTable table = new HTable(conf, tableName)) {
        regionCountActual = 0;
        NavigableMap<HRegionInfo, ServerName> regionLocations = table.getRegionLocations();
        for (Map.Entry<HRegionInfo, ServerName> entry : regionLocations.entrySet()) {
          HServerLoad serverLoad = admin.getClusterStatus().getLoad(entry.getValue());
          for (HServerLoad.RegionLoad regionLoad : serverLoad.getRegionsLoad().values()) {
            if (Arrays.equals(entry.getKey().getRegionName(), regionLoad.getName()))
              regionCountActual++;
          }
        }
        if (regionCountActual == regionCount) {
          return;
        }
      }
      Thread.sleep(WAIT_INTERVAL);
    }

    Assert.assertEquals(getMethodName() + " failed - ", regionCount, regionCountActual);
  }