Exemplo n.º 1
0
  private static void build(Iterable<String> in) throws IOException, InterruptedException {
    final List<String> args = newArrayList(in);
    Collections.sort(args);

    final int threads = Runtime.getRuntime().availableProcessors();

    final ExecutorService ex = Executors.newFixedThreadPool(threads);

    final String base = "base";
    new WithVm("base").createIfNotPresent();

    for (String pkg : args)
      ex.submit(
          () -> {
            final WithVm newVm = new WithVm("fbuild-" + pkg, TimeUnit.MINUTES.toMillis(30));

            final File rbuild = new File("wip-" + pkg + ".rbuild");
            try {
              newVm.cloneFrom(base);
              newVm.start();
              newVm.inTee(rbuild, "apt-get", "-oAPT::Get::Only-Source=true", "source", pkg);
              newVm.inTee(rbuild, "apt-get", "build-dep", "-y", "--force-yes", pkg);
              newVm.inTee(rbuild, "ifdown", "eth0");
              final boolean success =
                  0
                      == newVm.inTee(
                          rbuild, "sh", "-c", "cd " + pkg + "-* && dpkg-buildpackage -us -uc");
              newVm.stopNow();
              if (success) {
                rbuild.renameTo(new File("success-" + pkg + ".rbuild"));
                newVm.destroy();
                System.out.println("success: " + pkg);
              } else {
                rbuild.renameTo(new File("failure-" + pkg + ".rbuild"));
                System.out.println("failure: " + pkg);
              }
            } catch (Exception e) {
              rbuild.renameTo(new File("error-" + pkg + ".rbuild"));
              System.err.println("build error: " + pkg);
              e.printStackTrace();
              newVm.stopNow();
            }
            return null;
          });

    ex.shutdown();
    ex.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
  }
  @Test
  public void testEntriesAddition() throws Exception {

    createSchema(baseDocumentTx);
    createSchema(testDocumentTx);

    System.out.println("Start data propagation");

    List<Future> futures = new ArrayList<Future>();
    for (int i = 0; i < 5; i++) {
      futures.add(executorService.submit(new DataPropagationTask(baseDocumentTx, testDocumentTx)));
    }

    TimeUnit.MINUTES.sleep(5);

    System.out.println("Wait for process to destroy");
    serverProcess.destroy();

    serverProcess.waitFor();
    System.out.println("Process was destroyed");

    for (Future future : futures) {
      try {
        future.get();
      } catch (Exception e) {
        future.cancel(true);
      }
    }

    testDocumentTx =
        new ODatabaseDocumentTx(
            "plocal:" + buildDir.getAbsolutePath() + "/testUniqueIndexCrashRestore");
    testDocumentTx.open("admin", "admin");
    testDocumentTx.close();

    testDocumentTx.open("admin", "admin");

    System.out.println("Start data comparison.");
    compareIndexes();
  }