@Test
  public void addSimple() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(SUBSYSTEM_EMPTY, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    AddSecurityDomain addSecurityDomain = new AddSecurityDomain.Builder("creaperSecDomain").build();

    assertXmlIdentical(SUBSYSTEM_EMPTY, Files.toString(cfg, Charsets.UTF_8));
    client.apply(addSecurityDomain);
    assertXmlIdentical(SUBSYSTEM_SIMPLE, Files.toString(cfg, Charsets.UTF_8));
  }
  private ILayoutPullParser getParser(String layoutName, File xml) {
    if (layoutName.equals(mLayoutName)) {
      ILayoutPullParser parser = mLayoutEmbeddedParser;
      // The parser should only be used once!! If it is included more than once,
      // subsequent includes should just use a plain pull parser that is not tied
      // to the XML model
      mLayoutEmbeddedParser = null;
      return parser;
    }

    // For included layouts, create a ContextPullParser such that we get the
    // layout editor behavior in included layouts as well - which for example
    // replaces <fragment> tags with <include>.
    if (xml != null && xml.isFile()) {
      ContextPullParser parser = new ContextPullParser(this, xml);
      try {
        parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        String xmlText = Files.toString(xml, Charsets.UTF_8);
        parser.setInput(new StringReader(xmlText));
        return parser;
      } catch (XmlPullParserException e) {
        appendToIdeLog(e, null);
      } catch (FileNotFoundException e) {
        // Shouldn't happen since we check isFile() above
      } catch (IOException e) {
        appendToIdeLog(e, null);
      }
    }

    return null;
  }
  public void testCommon(String[] expectedResults, String physicalPlan, String resourceFile)
      throws Exception {
    try (RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();
        Drillbit bit = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {

      // run query.
      bit.run();
      client.connect();
      List<QueryDataBatch> results =
          client.runQuery(
              org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
              Files.toString(FileUtils.getResourceAsFile(physicalPlan), Charsets.UTF_8)
                  .replace("#{TEST_FILE}", resourceFile));

      RecordBatchLoader batchLoader = new RecordBatchLoader(bit.getContext().getAllocator());

      QueryDataBatch batch = results.get(0);
      assertTrue(batchLoader.load(batch.getHeader().getDef(), batch.getData()));

      int i = 0;
      for (VectorWrapper<?> v : batchLoader) {

        ValueVector.Accessor accessor = v.getValueVector().getAccessor();
        System.out.println(accessor.getObject(0));
        assertEquals(expectedResults[i++], accessor.getObject(0).toString());
      }

      batchLoader.clear();
      for (QueryDataBatch b : results) {
        b.release();
      }
    }
  }
@RunWith(MockitoJUnitRunner.class)
public class C4LakeviewOnDemandFetcherTest {

  private static final String API_ROOT = "http://api.channel4.com/pmlsd/";
  private static final String API_KEY = "api_key";
  private static final String BRAND = "blackout";
  private static final String P06_REQUEST_URI =
      API_ROOT + BRAND + "/4od.atom?platform=p06&apiKey=" + API_KEY;
  private static final String ITEM_URI =
      "http://www.channel4.com/programmes/" + BRAND + "/episode-guide/series-1/episode-1";

  private final SimpleHttpClient httpClient =
      new FixedResponseHttpClient(
          ImmutableMap.of(
              P06_REQUEST_URI,
              Files.toString(
                  new File(Resources.getResource("blackout.xml").getFile()), Charsets.UTF_8)));
  private final RemoteSiteClient<Feed> atomClient = new AtomClient(httpClient);

  private final C4LakeviewOnDemandFetcher fetcher =
      new C4LakeviewOnDemandFetcher(atomClient, API_KEY, null);

  public C4LakeviewOnDemandFetcherTest() throws IOException {}

  @Test
  public void testExtractsOnDemandForBrand() {
    Location location =
        fetcher.lakeviewLocationFor(
            ComplexItemTestDataBuilder.complexItem().withUri(ITEM_URI).build());

    assertEquals("https://ais.channel4.com/asset/3573948", location.getUri());
    assertEquals(Platform.XBOX, location.getPolicy().getPlatform());
  }
}
 private static String getHtmlTemplate(File assetsFolder, String htmlFileName) {
   try {
     return Files.toString(new File(assetsFolder, htmlFileName), Charsets.UTF_8);
   } catch (IOException e) {
     return "";
   }
 }
Exemple #6
0
  @Test(
      dataProvider = "GitConnectionFactory",
      dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
  public void testMergeConflict(GitConnectionFactory connectionFactory) throws Exception {
    // given
    GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
    connection.checkout(newDto(CheckoutRequest.class).withName(branchName).withCreateNew(true));
    addFile(connection, "t-merge-conflict", "aaa\n");
    connection.add(newDto(AddRequest.class).withFilepattern(new ArrayList<>(Arrays.asList("."))));
    connection.commit(newDto(CommitRequest.class).withMessage("add file in new branch"));

    connection.checkout(newDto(CheckoutRequest.class).withName("master"));
    addFile(connection, "t-merge-conflict", "bbb\n");
    connection.add(newDto(AddRequest.class).withFilepattern(new ArrayList<>(Arrays.asList("."))));
    connection.commit(newDto(CommitRequest.class).withMessage("add file in new branch"));
    // when
    MergeResult mergeResult = connection.merge(newDto(MergeRequest.class).withCommit(branchName));
    // then
    List<String> conflicts = mergeResult.getConflicts();
    assertEquals(conflicts.size(), 1);
    assertEquals(conflicts.get(0), "t-merge-conflict");

    assertEquals(mergeResult.getMergeStatus(), MergeResult.MergeStatus.CONFLICTING);

    String expContent =
        "<<<<<<< HEAD\n" //
            + "bbb\n" //
            + "=======\n" //
            + "aaa\n" //
            + ">>>>>>> MergeTestBranch\n";
    String actual =
        Files.toString(new File(connection.getWorkingDir(), "t-merge-conflict"), Charsets.UTF_8);
    assertEquals(actual, expContent);
  }
 private static String readFile(File file) {
   try {
     return Files.toString(file, Charsets.UTF_8);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
  @Test
  public void removeTcpHandler() throws Exception {
    File cfg = tmp.newFile("xmlTransform.xml");
    Files.write(TEST_TCP_SYSLOG_HANDLER, cfg, Charsets.UTF_8);

    OfflineManagementClient client =
        ManagementClient.offline(OfflineOptions.standalone().configurationFile(cfg).build());

    RemoveAuditLogSyslogHandler removeHandler =
        new RemoveAuditLogSyslogHandler("creaper-tcp-handler");

    assertXmlIdentical(TEST_TCP_SYSLOG_HANDLER, Files.toString(cfg, Charsets.UTF_8));

    client.apply(removeHandler);
    assertXmlIdentical(NO_HANDLERS, Files.toString(cfg, Charsets.UTF_8));
  }
  @Test
  public void testMultipleProvidersMixedSizes() throws Exception {
    RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();

    try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator()); ) {

      bit1.run();
      bit2.run();
      client.connect();
      List<QueryResultBatch> results =
          client.runQuery(
              org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
              Files.toString(
                  FileUtils.getResourceAsFile("/mergerecv/multiple_providers.json"),
                  Charsets.UTF_8));
      int count = 0;
      RecordBatchLoader batchLoader = new RecordBatchLoader(client.getAllocator());
      // print the results
      Long lastBlueValue = null;
      for (QueryResultBatch b : results) {
        count += b.getHeader().getRowCount();
        for (int valueIdx = 0; valueIdx < b.getHeader().getRowCount(); valueIdx++) {
          List<Object> row = Lists.newArrayList();
          batchLoader.load(b.getHeader().getDef(), b.getData());
          for (VectorWrapper vw : batchLoader) {
            row.add(
                vw.getValueVector().getField().toExpr()
                    + ":"
                    + vw.getValueVector().getAccessor().getObject(valueIdx));
            if (vw.getValueVector()
                .getField()
                .getAsSchemaPath()
                .getRootSegment()
                .getPath()
                .equals("blue")) {
              // assert order is ascending
              if (((Long) vw.getValueVector().getAccessor().getObject(valueIdx)).longValue() == 0)
                continue; // ignore initial 0's from sort
              if (lastBlueValue != null)
                assertTrue(
                    ((Long) vw.getValueVector().getAccessor().getObject(valueIdx)).longValue()
                        >= ((Long) lastBlueValue).longValue());
              lastBlueValue = (Long) vw.getValueVector().getAccessor().getObject(valueIdx);
            }
          }
          for (Object cell : row) {
            int len = cell.toString().length();
            System.out.print(cell + " ");
            for (int i = 0; i < (30 - len); ++i) System.out.print(" ");
          }
          System.out.println();
        }
        b.release();
        batchLoader.clear();
      }
      assertEquals(400, count);
    }
  }
 /** @deprecated since 0.7 */
 @Deprecated
 // Do this so that if there's a problem with our USERNAME's ssh key, we can still get in to check
 // TODO Once we're really confident there are not going to be regular problems, then delete this
 public static Statement addAuthorizedKeysToRoot(File publicKeyFile) throws IOException {
   String publicKey = Files.toString(publicKeyFile, Charsets.UTF_8);
   return addAuthorizedKeysToRoot(publicKey);
 }
  /**
   * There was a bug where `BuildTargetSourcePath` sources were written to the classes file using
   * their string representation, rather than their resolved path.
   */
  @Test
  public void shouldWriteResolvedBuildTargetSourcePathsToClassesFile()
      throws IOException, InterruptedException {
    BuildRuleResolver resolver = new BuildRuleResolver();
    SourcePathResolver pathResolver = new SourcePathResolver(resolver);
    BuildRule rule = new FakeBuildRule("//:fake", pathResolver);
    resolver.addToIndex(rule);

    Jsr199Javac javac = createJavac(/* withSyntaxError */ false);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    int exitCode =
        javac.buildWithClasspath(
            executionContext,
            createProjectFilesystem(),
            PATH_RESOLVER,
            BuildTargetFactory.newInstance("//some:example"),
            ImmutableList.<String>of(),
            SOURCE_PATHS,
            Optional.of(pathToSrcsList),
            Optional.<Path>absent());
    assertEquals("javac should exit with code 0.", exitCode, 0);

    File srcsListFile = pathToSrcsList.toFile();
    assertTrue(srcsListFile.exists());
    assertTrue(srcsListFile.isFile());
    assertEquals("Example.java", Files.toString(srcsListFile, Charsets.UTF_8).trim());
  }
Exemple #12
0
  @Test
  public void twoBitTwoExchangeTwoEntryRun() throws Exception {
    RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();

    try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator()); ) {

      bit1.run();
      bit2.run();
      client.connect();
      List<QueryResultBatch> results =
          client.runQuery(
              org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
              Files.toString(
                  FileUtils.getResourceAsFile("/sender/union_exchange.json"), Charsets.UTF_8));
      int count = 0;
      for (QueryResultBatch b : results) {
        if (b.getHeader().getRowCount() != 0) {
          count += b.getHeader().getRowCount();
        }
        b.release();
      }
      assertEquals(150, count);
    }
  }
Exemple #13
0
 @Test(
     dataProvider = "GitConnectionFactory",
     dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class)
 public void testResetSoft(GitConnectionFactory connectionFactory) throws Exception {
   // given
   GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
   File aaa = addFile(connection, "aaa", "aaa\n");
   FileOutputStream fos = new FileOutputStream(new File(connection.getWorkingDir(), "README.txt"));
   fos.write("MODIFIED\n".getBytes());
   fos.flush();
   fos.close();
   String initMessage = connection.log(newDto(LogRequest.class)).getCommits().get(0).getMessage();
   connection.add(newDto(AddRequest.class).withFilepattern(new ArrayList<>(Arrays.asList("."))));
   connection.commit(newDto(CommitRequest.class).withMessage("add file"));
   // when
   ResetRequest resetRequest = newDto(ResetRequest.class).withCommit("HEAD^");
   resetRequest.setType(ResetRequest.ResetType.SOFT);
   connection.reset(resetRequest);
   // then
   assertEquals(
       connection.log(newDto(LogRequest.class)).getCommits().get(0).getMessage(), initMessage);
   assertTrue(aaa.exists());
   assertEquals(connection.status(StatusFormat.SHORT).getAdded().get(0), "aaa");
   assertEquals(connection.status(StatusFormat.SHORT).getChanged().get(0), "README.txt");
   assertEquals(
       Files.toString(new File(connection.getWorkingDir(), "README.txt"), Charsets.UTF_8),
       "MODIFIED\n");
 }
  // specific tests should call this method, but it is not marked as a test itself intentionally
  public void testParquetFullEngineEventBased(
      boolean testValues,
      boolean generateNew,
      String plan,
      String readEntries,
      String filename,
      int numberOfTimesRead /* specified in json plan */,
      ParquetTestProperties props,
      QueryType queryType)
      throws Exception {
    if (generateNew) TestFileGenerator.generateParquetFile(filename, props);

    ParquetResultListener resultListener =
        new ParquetResultListener(getAllocator(), props, numberOfTimesRead, testValues);
    long C = System.nanoTime();
    String planText = Files.toString(FileUtils.getResourceAsFile(plan), Charsets.UTF_8);
    // substitute in the string for the read entries, allows reuse of the plan file for several
    // tests
    if (readEntries != null) {
      planText = planText.replaceFirst("&REPLACED_IN_PARQUET_TEST&", readEntries);
    }
    this.testWithListener(queryType, planText, resultListener);
    resultListener.getResults();
    long D = System.nanoTime();
    System.out.println(String.format("Took %f s to run query", (float) (D - C) / 1E9));
  }
  @Test
  public void testSubstringNegative(
      @Injectable final DrillbitContext bitContext,
      @Injectable UserServer.UserClientConnection connection)
      throws Throwable {

    new NonStrictExpectations() {
      {
        bitContext.getMetrics();
        result = new MetricRegistry();
        bitContext.getAllocator();
        result = new TopLevelAllocator();
        bitContext.getOperatorCreatorRegistry();
        result = new OperatorCreatorRegistry(c);
        bitContext.getConfig();
        result = c;
      }
    };

    PhysicalPlanReader reader =
        new PhysicalPlanReader(
            c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
    PhysicalPlan plan =
        reader.readPhysicalPlan(
            Files.toString(
                FileUtils.getResourceAsFile("/functions/testSubstringNegative.json"),
                Charsets.UTF_8));
    FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
    FragmentContext context =
        new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
    SimpleRootExec exec =
        new SimpleRootExec(
            ImplCreator.getExec(
                context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));

    while (exec.next()) {
      NullableVarCharVector c1 =
          exec.getValueVectorById(
              new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class);
      NullableVarCharVector.Accessor a1;
      a1 = c1.getAccessor();

      int count = 0;
      for (int i = 0; i < c1.getAccessor().getValueCount(); i++) {
        if (!a1.isNull(i)) {
          NullableVarCharHolder holder = new NullableVarCharHolder();
          a1.get(i, holder);
          // when offset is negative, substring return empty string.
          assertEquals("", holder.toString());
          ++count;
        }
      }
      assertEquals(50, count);
    }

    if (context.getFailureCause() != null) {
      throw context.getFailureCause();
    }
    assertTrue(!context.isFailed());
  }
Exemple #16
0
  public static void main(String[] args) {
    try {

      GsonFactory factory = new GsonFactory();
      List<TripOption> tripOptions =
          factory
              .fromString(
                  Files.toString(
                      new File("C:/projects/alacarte/backend/data/full_qpx.json"),
                      Charset.forName("UTF-8")),
                  TripsSearchResponse.class)
              .getTrips()
              .getTripOption();
      DataConverter dc = new DataConverter();
      /*
      ItineraryResults res = DataConverter.getItineraryResults(tripOptions);
      System.out.println(JSONUtil.write(res));
      System.out.println(JSONUtil.write(dc.getAxisData(tripOptions)));
      System.out.println(JSONUtil.write(dc.parseDate("2015-08-29T13:20+04:00")));
      */
      FlightSearchResults fsr = dc.getFlightSearchResults(tripOptions);
      System.out.println(JSONUtil.write(fsr));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /**
   * Highlights a word in an html file an returns the new file. The word comes from the GUI's query
   * text field. Also updates the term frequency field. (Cheeky).
   *
   * @param file
   * @return
   * @throws IOException
   */
  private File highlight(File file) throws IOException {

    File toLoad = null;
    String searchTerm = query.getText().trim();

    // Don't wanna highlight boolean terms
    // TOOD wildcards? Suppose you wouldn't see that syntax in the file
    // anyway...?
    searchTerm = searchTerm.replace(" AND ", " ");
    searchTerm = searchTerm.replace(" OR ", " ");
    searchTerm = searchTerm.replace(" NOT ", " ");

    // If not an empty search
    if (!StringUtils.isEmpty(searchTerm)) {

      String htmlString = Files.toString(file, Charset.defaultCharset());
      Highlighter hl = new Highlighter(searchTerm, htmlString);
      String newhtmlString = hl.getHighlightedHtml();
      termFrequency = hl.getTermFrequency();

      status.setText(statusResultsText + noOfResults + ", " + statusFrequencyText + termFrequency);
      ;
      // Write to a hidden temp file.
      String tempFilePath = file.getParent() + "/" + ".highlighted.htm";

      toLoad = new File(tempFilePath);

      FileUtils.writeStringToFile(toLoad, newhtmlString, Charset.defaultCharset());

    } else {
      System.out.println("[ERROR] Empty Search");
    }

    return toLoad;
  }
  private static ArrayList<SourceKey> createTree(String[] files) {
    ArrayList<SourceKey> ret = new ArrayList<SourceKey>();
    try {
      log("Processing Source Tree:");
      for (String file : files) {
        String data = Files.toString(new File(file), Charset.forName("UTF-8")).replaceAll("\r", "");
        String name = file.replace('\\', '/').substring(SRC.length() + 1);
        log("    " + name);
        CompilationUnit cu = Util.createUnit(parser, "1.6", name, data);

        ArrayList<TypeDeclaration> classes = new ArrayList<TypeDeclaration>();
        List<AbstractTypeDeclaration> types = (List<AbstractTypeDeclaration>) cu.types();
        for (AbstractTypeDeclaration type : types) {
          TREE.processClass(type);
          if (type instanceof TypeDeclaration) {
            classes.add((TypeDeclaration) type);
          }
        }
        ret.add(new SourceKey(name.substring(0, name.length() - 5), cu, data.trim(), classes));
      }

      for (String lib : libs) {
        // log("Processing Tree: " + lib);
        TREE.processLibrary(new File(lib));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return ret;
  }
  @Test
  public void TestMultipleSendLocationBroadcastExchange() throws Exception {
    RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();

    try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {

      bit1.run();
      bit2.run();
      client.connect();

      String physicalPlan =
          Files.toString(
              FileUtils.getResourceAsFile("/sender/broadcast_exchange_long_run.json"),
              Charsets.UTF_8);
      List<QueryResultBatch> results = client.runQuery(QueryType.PHYSICAL, physicalPlan);
      int count = 0;
      for (QueryResultBatch b : results) {
        if (b.getHeader().getRowCount() != 0) count += b.getHeader().getRowCount();
        b.release();
      }
      System.out.println(count);
    }
  }
  @Test
  public void test() throws Exception {
    assertTrue(
        "SonarQube 5.1 is the minimum version to generate the issues report, change your orchestrator.properties",
        orchestrator.getConfiguration().getSonarVersion().isGreaterThanOrEquals("5.1"));
    File litsDifferencesFile = FileLocation.of("target/differences").getFile();
    SonarRunner build =
        SonarRunner.create(FileLocation.of("../sources/src").getFile())
            .setProjectKey("project")
            .setProjectName("project")
            .setProjectVersion("1")
            .setLanguage("js")
            .setSourceDirs("./")
            .setSourceEncoding("utf-8")
            .setProfile("rules")
            .setProperty("sonar.analysis.mode", "preview")
            .setProperty("sonar.issuesReport.html.enable", "true")
            .setProperty(
                "dump.old", FileLocation.of("src/test/expected").getFile().getAbsolutePath())
            .setProperty("dump.new", FileLocation.of("target/actual").getFile().getAbsolutePath())
            .setProperty("lits.differences", litsDifferencesFile.getAbsolutePath())
            .setProperty("sonar.cpd.skip", "true")
            .setEnvironmentVariable("SONAR_RUNNER_OPTS", "-Xmx1024m");
    orchestrator.executeBuild(build);

    assertThat(Files.toString(litsDifferencesFile, StandardCharsets.UTF_8)).isEmpty();
  }
  public static void compareNamespaces(
      @NotNull NamespaceDescriptor nsa,
      @NotNull NamespaceDescriptor nsb,
      boolean includeObject,
      @NotNull File txtFile) {
    String serialized = new NamespaceComparator(includeObject).doCompareNamespaces(nsa, nsb);
    try {
      for (; ; ) {
        String expected = Files.toString(txtFile, Charset.forName("utf-8")).replace("\r\n", "\n");

        if (expected.contains("kick me")) {
          // for developer
          System.err.println("generating " + txtFile);
          Files.write(serialized, txtFile, Charset.forName("utf-8"));
          continue;
        }

        // compare with hardcopy: make sure nothing is lost in output
        Assert.assertEquals(expected, serialized);
        break;
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
  @Test
  public void TestSingleBroadcastExchangeWithTwoScans() throws Exception {
    RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();

    try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
        Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
        DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {

      bit1.run();
      bit2.run();
      client.connect();

      String physicalPlan =
          Files.toString(
                  FileUtils.getResourceAsFile("/sender/broadcast_exchange.json"), Charsets.UTF_8)
              .replace(
                  "#{LEFT_FILE}",
                  FileUtils.getResourceAsFile("/join/merge_single_batch.left.json")
                      .toURI()
                      .toString())
              .replace(
                  "#{RIGHT_FILE}",
                  FileUtils.getResourceAsFile("/join/merge_single_batch.right.json")
                      .toURI()
                      .toString());
      List<QueryResultBatch> results = client.runQuery(QueryType.PHYSICAL, physicalPlan);
      int count = 0;
      for (QueryResultBatch b : results) {
        if (b.getHeader().getRowCount() != 0) count += b.getHeader().getRowCount();
        b.release();
      }
      assertEquals(25, count);
    }
  }
    private void installSecondaryDexFiles() throws Exception {
      final ImmutableMap<String, Path> hashToSources = getRequiredDexFiles();
      final ImmutableSet<String> requiredHashes = hashToSources.keySet();
      final ImmutableSet<String> presentHashes = prepareSecondaryDexDir(requiredHashes);
      final Set<String> hashesToInstall = Sets.difference(requiredHashes, presentHashes);

      Map<String, Path> filesToInstallByHash =
          Maps.filterKeys(hashToSources, Predicates.in(hashesToInstall));

      // This is a bit gross.  It was a late addition.  Ideally, we could eliminate this, but
      // it wouldn't be terrible if we don't.  We store the dexed jars on the device
      // with the full SHA-1 hashes in their names.  This is the format that the loader uses
      // internally, so ideally we would just load them in place.  However, the code currently
      // expects to be able to copy the jars from a directory that matches the name in the
      // metadata file, like "secondary-1.dex.jar".  We don't want to give up putting the
      // hashes in the file names (because we use that to skip re-uploads), so just hack
      // the metadata file to have hash-like names.
      String metadataContents =
          com.google.common.io.Files.toString(
                  projectFilesystem
                      .resolve(exopackageInfo.getDexInfo().get().getMetadata())
                      .toFile(),
                  Charsets.UTF_8)
              .replaceAll(
                  "secondary-(\\d+)\\.dex\\.jar (\\p{XDigit}{40}) ", "secondary-$2.dex.jar $2 ");

      installFiles(
          "secondary_dex",
          ImmutableMap.copyOf(filesToInstallByHash),
          metadataContents,
          "secondary-%s.dex.jar",
          SECONDARY_DEX_DIR);
    }
Exemple #24
0
  public static void processSongs(String dataFolder, String out) {

    File outfile = new File(out);

    File songdata = new File(dataFolder);
    File[] files =
        songdata.listFiles(
            new FileFilter() {
              public boolean accept(File pathname) {
                if (pathname.getName().endsWith(".xml")) return true;
                return false;
              }
            });

    for (File file : files) {
      try {
        songTransformer.addSong(Files.toString(file, Charsets.UTF_8));
      } catch (IOException e) {
        throw new IllegalStateException(e);
      }
    }

    Map<File, Object> generate = songTransformer.generate(outfile);
    ChordsMl.writeGenerated(generate);
    System.out.println(
        "to create pdf type: cd "
            + outfile.getParentFile().getAbsolutePath()
            + ";"
            + " pdflatex "
            + outfile.getName());
  }
 public List<JavaScriptSource> setUpSource(JobConf job) {
   List<JavaScriptSource> js = new ArrayList<JavaScriptSource>();
   js.add(
       new JavaScriptSource("emit.js", "function emit(k,v){$mapper.emit(k,v,$output_collector)}"));
   js.add(new JavaScriptSource("map.js", job.get("map.js")));
   js.add(new JavaScriptSource("reduce.js", job.get("reduce.js")));
   js.add(new JavaScriptSource("functions.js", job.get("functions.js")));
   js.add(new JavaScriptSource("filter.js", job.get("filter.js")));
   js.add(new JavaScriptSource("query_id", job.get("query_id")));
   try {
     Path[] files = DistributedCache.getLocalCacheFiles(job);
     if (files != null) {
       for (int i = 0; i < files.length; i++) {
         Path path = files[i];
         if (path.getName().endsWith(".js")) {
           String source = Files.toString(new File(path.toString()), Charset.forName("UTF-8"));
           js.add(new JavaScriptSource(path.getName(), source));
         }
       }
     }
   } catch (IOException ioe) {
     throw new RuntimeException("Couldn't read from DistributedCache", ioe);
   }
   return js;
 }
  @Override
  public void init() {
    wifiChannelMap = HashBiMap.create();
    wifiChannelMap.put(2412, "2.4G Ch01");
    wifiChannelMap.put(2417, "2.4G Ch02");
    wifiChannelMap.put(2422, "2.4G Ch03");
    wifiChannelMap.put(2427, "2.4G Ch04");
    wifiChannelMap.put(2432, "2.4G Ch05");
    wifiChannelMap.put(2437, "2.4G Ch06");
    wifiChannelMap.put(2442, "2.4G Ch07");
    wifiChannelMap.put(2447, "2.4G Ch08");
    wifiChannelMap.put(2452, "2.4G Ch09");
    wifiChannelMap.put(2457, "2.4G Ch10");
    wifiChannelMap.put(2462, "2.4G Ch11");
    wifiChannelMap.put(2467, "2.4G Ch12");
    wifiChannelMap.put(2472, "2.4G Ch13");
    wifiChannelMap.put(2484, "2.4G Ch14");

    wifi = (WifiManager) hardwareMap.appContext.getSystemService(Context.WIFI_SERVICE);
    hardwareMap.appContext.registerReceiver(
        new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
            LinkedList<ScanResult> results = new LinkedList<>(wifi.getScanResults());
            scanResults(results);
          }
        },
        new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));

    wifi.startScan();

    try {
      String absolutePath = hardwareMap.appContext.getFilesDir().getAbsolutePath() + "/";
      RunShellCommand cmd = new RunShellCommand();
      String output;
      if ((output =
                  cmd.run(
                      String.format(
                          "cp /data/misc/wifi/p2p_supplicant.conf %sp2p_supplicant.conf \n",
                          absolutePath)))
              .length()
          > 0) {
        RobotLog.e("Cannot copy p2p file" + output);
        operChannel = output;
      }

      String fileData =
          Files.toString(new File(absolutePath + "p2p_supplicant.conf"), Charset.defaultCharset());
      String[] datas = fileData.split("/n");
      for (String data : datas) {
        if (data.contains("p2p_oper_channel")) {
          operChannel = data.substring(data.indexOf("="));
        }
      }
    } catch (IOException ex) {
      if (operChannel.equals("")) {
        operChannel = ex.getMessage();
      }
    }
  }
Exemple #27
0
 private void saveLinesMetric() {
   try {
     String content = Files.toString(context.getFile(), charset);
     saveMetricOnFile(CoreMetrics.LINES, content.split("(\r)?\n|\r", -1).length);
   } catch (IOException e) {
     Throwables.propagate(e);
   }
 }
 public String getContent() throws IOException {
   if (type == Type.FILE) {
     return Files.toString(new File(name), Charsets.UTF_8);
   } else {
     URL url = getClass().getResource(name);
     return Resources.toString(url, Charsets.UTF_8);
   }
 }
 @HotEventHandler
 public void handleOrderEnd(OrderFinishedEvent e) throws IOException {
   String lines = Files.toString(resultfile, Charset.defaultCharset());
   logger.debug("resultfile is " + resultfile.getName() + "\n" + lines);
   assertParameter(lines, "RESULT_FILE", resultfile.getAbsolutePath());
   assertParameter(lines, "ORDER_PARAM", "ORDER_PARAM");
   assertParameter(lines, "JOB_PARAM", "JOB_PARAM");
   controller().terminateScheduler();
 }
  @Test
  public void testLinkedBlockingQueueWithFile() throws InterruptedException, IOException {
    BlockingQueue<File> queue = Queues.newLinkedBlockingQueue();

    for (int i = 1; i < 4; i++) queue.put(new File(String.format("src/test/resources/%d.log", i)));

    File f;
    while ((f = queue.poll()) != null) System.out.println(Files.toString(f, Charsets.UTF_8));
  }