Tabnine Logo
FileChecksumMatcher
Code IndexAdd Tabnine to your IDE (free)

How to use
FileChecksumMatcher
in
org.apache.beam.sdk.testing

Best Java code snippets using org.apache.beam.sdk.testing.FileChecksumMatcher (Showing top 15 results out of 315)

origin: org.apache.beam/beam-sdks-java-core

/**
 * Computes a checksum of the sharded file specified in the constructor. Not safe to call until
 * the writing is complete.
 */
private String getActualChecksum() {
 if (actualChecksum == null) {
  // Load output data
  List<String> outputs;
  try {
   outputs = shardedFile.readFilesWithRetries(Sleeper.DEFAULT, BACK_OFF_FACTORY.backoff());
  } catch (Exception e) {
   throw new RuntimeException(String.format("Failed to read from: %s", shardedFile), e);
  }
  // Verify outputs. Checksum is computed using SHA-1 algorithm
  actualChecksum = computeHash(outputs);
  LOG.debug("Generated checksum: {}", actualChecksum);
 }
 return actualChecksum;
}
origin: org.apache.beam/beam-sdks-java-core

@Override
public boolean matchesSafely(PipelineResult pipelineResult) {
 return getActualChecksum().equals(expectedChecksum);
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testMatcherThatVerifiesSingleFile() throws IOException {
 File tmpFile = tmpFolder.newFile("result-000-of-001");
 Files.write("Test for file checksum verifier.", tmpFile, StandardCharsets.UTF_8);
 FileChecksumMatcher matcher =
   new FileChecksumMatcher("a8772322f5d7b851777f820fc79d050f9d302915", tmpFile.getPath());
 assertThat(pResult, matcher);
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testMatcherThatVerifiesFileWithEmptyContent() throws IOException {
 File emptyFile = tmpFolder.newFile("result-000-of-001");
 Files.write("", emptyFile, StandardCharsets.UTF_8);
 FileChecksumMatcher matcher =
   new FileChecksumMatcher(
     "da39a3ee5e6b4b0d3255bfef95601890afd80709",
     tmpFolder.getRoot().toPath().resolve("*").toString());
 assertThat(pResult, matcher);
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testPreconditionFilePathIsEmpty() {
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage(containsString("Expected valid file path, but received"));
 new FileChecksumMatcher("checksumString", "");
}
origin: org.apache.beam/beam-sdks-java-core

 @Override
 public void describeMismatchSafely(PipelineResult pResult, Description description) {
  description.appendText("was (").appendText(getActualChecksum()).appendText(")");
 }
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testPreconditionChecksumIsEmpty() throws IOException {
 String tmpPath = tmpFolder.newFile().getPath();
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage(containsString("Expected valid checksum, but received"));
 new FileChecksumMatcher("", tmpPath);
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testPreconditionChecksumIsNull() throws IOException {
 String tmpPath = tmpFolder.newFile().getPath();
 thrown.expect(IllegalArgumentException.class);
 thrown.expectMessage(containsString("Expected valid checksum, but received"));
 new FileChecksumMatcher(null, tmpPath);
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testPreconditionShardTemplateIsNull() throws IOException {
 String tmpPath = tmpFolder.newFile().getPath();
 thrown.expect(NullPointerException.class);
 thrown.expectMessage(
   containsString(
     "Expected non-null shard pattern. "
       + "Please call the other constructor to use default pattern:"));
 new FileChecksumMatcher("checksumString", tmpPath, null);
}
origin: org.apache.beam/beam-sdks-java-core

 @Test
 public void testMatcherThatUsesCustomizedTemplate() throws Exception {
  // Customized template: resultSSS-totalNNN
  File tmpFile1 = tmpFolder.newFile("result0-total2");
  File tmpFile2 = tmpFolder.newFile("result1-total2");
  Files.write("To be or not to be, ", tmpFile1, StandardCharsets.UTF_8);
  Files.write("it is not a question.", tmpFile2, StandardCharsets.UTF_8);

  Pattern customizedTemplate =
    Pattern.compile("(?x) result (?<shardnum>\\d+) - total (?<numshards>\\d+)");
  FileChecksumMatcher matcher =
    new FileChecksumMatcher(
      "90552392c28396935fe4f123bd0b5c2d0f6260c8",
      tmpFolder.getRoot().toPath().resolve("*").toString(),
      customizedTemplate);

  assertThat(pResult, matcher);
 }
}
origin: org.apache.beam/beam-sdks-java-core

@Test
public void testMatcherThatVerifiesMultipleFiles() throws IOException {
 File tmpFile1 = tmpFolder.newFile("result-000-of-002");
 File tmpFile2 = tmpFolder.newFile("result-001-of-002");
 File tmpFile3 = tmpFolder.newFile("tmp");
 Files.write("To be or not to be, ", tmpFile1, StandardCharsets.UTF_8);
 Files.write("it is not a question.", tmpFile2, StandardCharsets.UTF_8);
 Files.write("tmp", tmpFile3, StandardCharsets.UTF_8);
 FileChecksumMatcher matcher =
   new FileChecksumMatcher(
     "90552392c28396935fe4f123bd0b5c2d0f6260c8",
     tmpFolder.getRoot().toPath().resolve("result-*").toString());
 assertThat(pResult, matcher);
}
origin: org.apache.beam/beam-examples-java

 @Test
 public void testE2EWordCount() throws Exception {
  WordCountITOptions options = TestPipeline.testingPipelineOptions().as(WordCountITOptions.class);

  options.setInputFile(DEFAULT_INPUT);
  options.setOutput(
    FileSystems.matchNewResource(options.getTempRoot(), true)
      .resolve(
        String.format("WordCountIT-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
        StandardResolveOptions.RESOLVE_DIRECTORY)
      .resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
      .resolve("results", StandardResolveOptions.RESOLVE_FILE)
      .toString());
  options.setOnSuccessMatcher(
    new FileChecksumMatcher(DEFAULT_OUTPUT_CHECKSUM, options.getOutput() + "*-of-*"));

  WordCount.runWordCount(options);
 }
}
origin: org.apache.beam/beam-examples-java

 @Test
 public void testE2ETopWikiPages() throws Exception {
  TopWikipediaSessionsITOptions options =
    TestPipeline.testingPipelineOptions().as(TopWikipediaSessionsITOptions.class);

  options.setWikiInput(DEFAULT_INPUT_10_FILES);
  options.setOutput(
    FileSystems.matchNewResource(options.getTempRoot(), true)
      .resolve(
        String.format("topwikisessions-it-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
        StandardResolveOptions.RESOLVE_DIRECTORY)
      .resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
      .resolve("results", StandardResolveOptions.RESOLVE_FILE)
      .toString());
  options.setOnSuccessMatcher(
    new FileChecksumMatcher(DEFAULT_OUTPUT_CHECKSUM, options.getOutput() + "*-of-*"));

  TopWikipediaSessions.run(options);
 }
}
origin: org.apache.beam/beam-examples-java

 @Test
 public void testE2ETfIdf() throws Exception {
  TfIdfITOptions options = TestPipeline.testingPipelineOptions().as(TfIdfITOptions.class);
  options.setInput(DEFAULT_INPUT);
  options.setOutput(
    FileSystems.matchNewResource(options.getTempRoot(), true)
      .resolve(
        String.format("TfIdfIT-%tF-%<tH-%<tM-%<tS-%<tL", new Date()),
        StandardResolveOptions.RESOLVE_DIRECTORY)
      .resolve("output", StandardResolveOptions.RESOLVE_DIRECTORY)
      .resolve("results", StandardResolveOptions.RESOLVE_FILE)
      .toString());
  options.setOnSuccessMatcher(
    new FileChecksumMatcher(
      EXPECTED_OUTPUT_CHECKSUM, options.getOutput() + "*-of-*.csv", DEFAULT_SHARD_TEMPLATE));

  TfIdf.runTfIdf(options);
 }
}
origin: org.apache.beam/beam-sdks-java-core

new FileChecksumMatcher(
  VALUE_CHECKSUM, new FilePatternMatchingShardedFile(singleOutputPrefix + "*")),
new FileChecksumMatcher(
  VALUE_CHECKSUM, new FilePatternMatchingShardedFile(multiOutputPrefix + "*"))));
org.apache.beam.sdk.testingFileChecksumMatcher

Javadoc

Matcher to verify file checksum in E2E test.

For example:

 
assertThat(job, new FileChecksumMatcher(checksumString, filePath));
or
 
assertThat(job, new FileChecksumMatcher(checksumString, filePath, shardTemplate));

Checksum of outputs is generated based on SHA-1 algorithm. If output file is empty, SHA-1 hash of empty string (da39a3ee5e6b4b0d3255bfef95601890afd80709) is used as expected.

Most used methods

  • <init>
    Constructor using an entirely custom ShardedFile implementation.For internal use only.
  • computeHash
  • getActualChecksum
    Computes a checksum of the sharded file specified in the constructor. Not safe to call until the wri

Popular in Java

  • Making http requests using okhttp
  • findViewById (Activity)
  • getSharedPreferences (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now