com.google.errorprone.annotations.MustBeClosed Java Examples

The following examples show how to use com.google.errorprone.annotations.MustBeClosed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenCensusTracerAdapter.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("MustBeClosedChecker")
@MustBeClosed
@Override
public Scope activateSpan(Span span) {
  final io.opencensus.trace.Span newSpan;

  if (span instanceof OpenCensusSpanAdapter) {
    final OpenCensusSpanAdapter realSpan = (OpenCensusSpanAdapter) span;
    newSpan = realSpan.getOCSpan();
  } else {
    // Cannot activate non open census spans.
    // Also, noop spans should be remembered internally as blank spans.
    newSpan = BlankSpan.INSTANCE;
  }

  // This can only be called with an adapted span.
  return new OpenCensusScopeAdapter(ocTracer.withSpan(newSpan));
}
 
Example #2
Source File: TransactionTestSuite.java    From cava with Apache License 2.0 6 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> readTransactionTests() throws IOException {
  return Resources
      .find("**/TransactionTests/**/*.json")
      .filter(
          url -> !url.getPath().contains("GasLimitOverflow")
              && !url.getPath().contains("GasLimitxPriceOverflow")
              && !url.getPath().contains("NotEnoughGas")
              && !url.getPath().contains("NotEnoughGAS")
              && !url.getPath().contains("EmptyTransaction"))
      .flatMap(url -> {
        try (InputStream in = url.openConnection().getInputStream()) {
          return readTestCase(in);
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      })
      .sorted(Comparator.comparing(a -> ((String) a.get()[0])));
}
 
Example #3
Source File: ShufflingTestFinder.java    From teku with Apache License 2.0 6 votes vote down vote up
@Override
@MustBeClosed
public Stream<TestDefinition> findTests(final String spec, final Path testRoot)
    throws IOException {
  final Path shufflingDir = testRoot.resolve(SHUFFLING_TEST_CATEGORY);
  if (!shufflingDir.toFile().exists()) {
    return Stream.empty();
  }
  return Files.walk(shufflingDir)
      .filter(path -> path.resolve("mapping.yaml").toFile().exists())
      .map(
          testDir -> {
            final String testName = shufflingDir.relativize(testDir).toString();
            return new TestDefinition(
                spec, SHUFFLING_TEST_CATEGORY, testName, testRoot.relativize(testDir));
          });
}
 
Example #4
Source File: TransactionTestSuite.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> readTransactionTests() throws IOException {
  return Resources
      .find("**/TransactionTests/**/*.json")
      .filter(
          url -> !url.getPath().contains("GasLimitOverflow")
              && !url.getPath().contains("GasLimitxPriceOverflow")
              && !url.getPath().contains("NotEnoughGas")
              && !url.getPath().contains("NotEnoughGAS")
              && !url.getPath().contains("EmptyTransaction"))
      .flatMap(url -> {
        try (InputStream in = url.openConnection().getInputStream()) {
          return readTestCase(in);
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      })
      .sorted(Comparator.comparing(a -> ((String) a.get()[0])));
}
 
Example #5
Source File: SszTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
@MustBeClosed
public Stream<TestDefinition> findTests(final String spec, final Path testRoot)
    throws IOException {
  final Path sszStaticDir = testRoot.resolve(testDirectoryName);
  if (!sszStaticDir.toFile().exists()) {
    return Stream.empty();
  }
  return Files.list(sszStaticDir)
      .flatMap(unchecked(dir -> findSszStaticTests(spec, testRoot, dir)));
}
 
Example #6
Source File: SSZTestSuite.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> findTests(String glob) throws IOException {
  return Resources.find(glob).flatMap(url -> {
    try (InputStream in = url.openConnection().getInputStream()) {
      return prepareTests(in);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  });
}
 
Example #7
Source File: BlockRLPTestSuite.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> readBlockChainTests() throws IOException {
  return Resources.find("**/BlockchainTests/**/*.json").flatMap(url -> {
    try (InputStream is = url.openConnection().getInputStream()) {
      return readTestCase(is);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }).filter(Objects::nonNull);
}
 
Example #8
Source File: MerkleTrieTestSuite.java    From cava with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> findTests(String glob) throws IOException {
  return Resources.find(glob).flatMap(url -> {
    try (InputStream in = url.openConnection().getInputStream()) {
      return prepareTests(in);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  });
}
 
Example #9
Source File: RLPReferenceTestSuite.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> findTests(String glob) throws IOException {
  return Resources.find(glob).flatMap(url -> {
    try (InputStream in = url.openConnection().getInputStream()) {
      return prepareTests(in);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  });
}
 
Example #10
Source File: Resources.java    From incubator-tuweni with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<URL> find(URL baseUrl, String glob) throws IOException {
  if (!isJarURL(baseUrl)) {
    return findFileResources(baseUrl, glob);
  } else {
    return findJarResources(baseUrl, glob);
  }
}
 
Example #11
Source File: BlsTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
@MustBeClosed
public Stream<TestDefinition> findTests(final String spec, final Path testRoot)
    throws IOException {
  final Path blsTestDir = testRoot.resolve("bls");
  if (!blsTestDir.toFile().exists()) {
    return Stream.empty();
  }
  return Files.list(blsTestDir).flatMap(unchecked(dir -> findBlsTests(spec, testRoot, dir)));
}
 
Example #12
Source File: RLPReferenceTestSuite.java    From cava with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> findTests(String glob) throws IOException {
  return Resources.find(glob).flatMap(url -> {
    try (InputStream in = url.openConnection().getInputStream()) {
      return prepareTests(in);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  });
}
 
Example #13
Source File: BlockRLPTestSuite.java    From cava with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<Arguments> readBlockChainTests() throws IOException {
  return Resources.find("**/BlockchainTests/**/*.json").flatMap(url -> {
    try (InputStream is = url.openConnection().getInputStream()) {
      return readTestCase(is);
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  });
}
 
Example #14
Source File: Resources.java    From cava with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<URL> find(URL baseUrl, String glob) throws IOException {
  if (!isJarURL(baseUrl)) {
    return findFileResources(baseUrl, glob);
  } else {
    return findJarResources(baseUrl, glob);
  }
}
 
Example #15
Source File: ConsoleLogReaderFactory.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a new {@link Reader} for the file.
 *
 * @return a reader
 */
@Override
@MustBeClosed
public Reader create() {
    try {
        return run.getLogReader();
    }
    catch (IOException e) {
        throw new ParsingException(e);
    }
}
 
Example #16
Source File: ReferenceTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<TestDefinition> findTestTypes(final Path specDirectory) {
  final String spec = specDirectory.getFileName().toString();
  final Path phase0Tests = specDirectory.resolve(PHASE_TEST_DIR);
  return Stream.of(
          new BlsTestFinder(),
          new SszTestFinder("ssz_generic"),
          new SszTestFinder("ssz_static"),
          new ShufflingTestFinder(),
          new PyspecTestFinder())
      .flatMap(unchecked(finder -> finder.findTests(spec, phase0Tests)));
}
 
Example #17
Source File: BlsTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private Stream<TestDefinition> findBlsTests(
    final String spec, final Path testRoot, final Path testCategoryDir) throws IOException {
  final String testType = testRoot.relativize(testCategoryDir).toString();
  return Files.walk(testCategoryDir)
      .filter(path -> path.resolve(BLS_DATA_FILE).toFile().exists())
      .map(
          testDir -> {
            final String testName = testCategoryDir.relativize(testDir).toString();
            return new TestDefinition(spec, testType, testName, testRoot.relativize(testDir));
          });
}
 
Example #18
Source File: RocksDbIterator.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
public static <K, V> RocksDbIterator<K, V> create(
    final RocksDbColumn<K, V> column,
    final RocksIterator rocksIt,
    final Predicate<K> continueTest,
    final Supplier<Boolean> isDatabaseClosed) {
  return new RocksDbIterator<>(column, rocksIt, continueTest, isDatabaseClosed);
}
 
Example #19
Source File: SszTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<TestDefinition> findSszStaticTests(
    final String spec, final Path phase0Tests, final Path testCategoryDir) throws IOException {
  final String testType = phase0Tests.relativize(testCategoryDir).toString();
  return Files.walk(testCategoryDir)
      .filter(path -> path.resolve("serialized.ssz").toFile().exists())
      .map(
          testDir -> {
            final String testName = testCategoryDir.relativize(testDir).toString();
            return new TestDefinition(spec, testType, testName, phase0Tests.relativize(testDir));
          });
}
 
Example #20
Source File: Main.java    From bazel-tools with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
@Override
public Stream<Path> findFilesMatching(final Path directory, final String syntaxAndPattern)
    throws IOException {
  final PathMatcher matcher = directory.getFileSystem().getPathMatcher(syntaxAndPattern);
  return Files.find(
      directory, Integer.MAX_VALUE, (p, a) -> matcher.matches(p) && !a.isDirectory());
}
 
Example #21
Source File: PyspecTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
@MustBeClosed
public Stream<TestDefinition> findTests(final String spec, final Path testRoot)
    throws IOException {
  return Files.walk(testRoot)
      .filter(path -> path.resolve(PYSPEC_TEST_DIRECTORY_NAME).toFile().exists())
      .flatMap(
          unchecked(testCategoryDir -> findPyspecTestCases(spec, testRoot, testCategoryDir)));
}
 
Example #22
Source File: PyspecTestFinder.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
private static Stream<TestDefinition> findPyspecTestCases(
    final String spec, final Path testRoot, final Path testCategoryDir) throws IOException {
  final String testType = testRoot.relativize(testCategoryDir).toString();
  final Path pyspecDir = testCategoryDir.resolve(PYSPEC_TEST_DIRECTORY_NAME);
  return Files.list(pyspecDir)
      .map(
          testDir -> {
            final String testName = pyspecDir.relativize(testDir).toString();
            return new TestDefinition(spec, testType, testName, testRoot.relativize(testDir));
          });
}
 
Example #23
Source File: ManualReferenceTestRunner.java    From teku with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@MustBeClosed
static Stream<Arguments> loadReferenceTests() throws IOException {
  return ReferenceTestFinder.findReferenceTests()
      .filter(testDefinition -> SPEC.isBlank() || testDefinition.getSpec().equalsIgnoreCase(SPEC))
      .filter(testDefinition -> testDefinition.getTestType().startsWith(TEST_TYPE))
      .map(testDefinition -> Arguments.of(testDefinition.getDisplayName(), testDefinition));
}
 
Example #24
Source File: ReferenceTests.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
static Stream<Arguments> getExpandMessageTestCases() {
  final JSONParser parser = new JSONParser();
  final ArrayList<Arguments> argumentsList = new ArrayList<>();

  try {
    final Reader reader = new FileReader(pathToExpandMessageTests.toFile(), US_ASCII);
    final JSONObject refTests = (JSONObject) parser.parse(reader);

    final Bytes dst = Bytes.wrap(((String) refTests.get("DST")).getBytes(US_ASCII));

    final JSONArray tests = (JSONArray) refTests.get("tests");
    int idx = 0;
    for (Object o : tests) {
      JSONObject test = (JSONObject) o;
      Bytes message = Bytes.wrap(((String) test.get("msg")).getBytes(US_ASCII));
      int length = Integer.parseInt(((String) test.get("len_in_bytes")).substring(2), 16);
      Bytes uniformBytes = Bytes.fromHexString((String) test.get("uniform_bytes"));
      argumentsList.add(
          Arguments.of(
              pathToExpandMessageTests.toString(), idx++, dst, message, length, uniformBytes));
    }
  } catch (IOException | ParseException e) {
    throw new RuntimeException(e);
  }

  return argumentsList.stream();
}
 
Example #25
Source File: ReferenceTests.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
static Stream<Arguments> hashG2TestCases() {
  final JSONParser parser = new JSONParser();
  final ArrayList<Arguments> argumentsList = new ArrayList<>();

  try {
    final Reader reader = new FileReader(pathToHashG2Tests.toFile(), US_ASCII);
    final JSONObject refTests = (JSONObject) parser.parse(reader);

    final Bytes dst = Bytes.wrap(((String) refTests.get("dst")).getBytes(US_ASCII));

    final JSONArray tests = (JSONArray) refTests.get("vectors");
    int idx = 0;
    for (Object o : tests) {
      JSONObject test = (JSONObject) o;
      Bytes message = Bytes.wrap(((String) test.get("msg")).getBytes(US_ASCII));
      JacobianPoint p = getPoint((JSONObject) test.get("P"));
      JacobianPoint q0 = getPoint((JSONObject) test.get("Q0"));
      JacobianPoint q1 = getPoint((JSONObject) test.get("Q1"));
      JSONArray uArray = (JSONArray) test.get("u");
      FP2Immutable[] u = {
        getFieldPoint((String) uArray.get(0)), getFieldPoint((String) uArray.get(1))
      };
      argumentsList.add(
          Arguments.of(pathToExpandMessageTests.toString(), idx++, dst, message, u, q0, q1, p));
    }
  } catch (IOException | ParseException e) {
    throw new RuntimeException(e);
  }

  return argumentsList.stream();
}
 
Example #26
Source File: V4FinalizedRocksDbDao.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
@MustBeClosed
public Stream<SignedBeaconBlock> streamFinalizedBlocks(
    final UnsignedLong startSlot, final UnsignedLong endSlot) {
  return db.stream(V4SchemaFinalized.FINALIZED_BLOCKS_BY_SLOT, startSlot, endSlot)
      .map(ColumnEntry::getValue);
}
 
Example #27
Source File: V3RocksDbDao.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
@MustBeClosed
public Stream<SignedBeaconBlock> streamFinalizedBlocks(
    final UnsignedLong startSlot, final UnsignedLong endSlot) {
  return db.stream(V3Schema.FINALIZED_ROOTS_BY_SLOT, startSlot, endSlot)
      .map(ColumnEntry::getValue)
      .flatMap(root -> getFinalizedBlock(root).stream());
}
 
Example #28
Source File: RocksDbIterator.java    From teku with Apache License 2.0 5 votes vote down vote up
@MustBeClosed
public Stream<ColumnEntry<TKey, TValue>> toStream() {
  assertOpen();
  final Spliterator<ColumnEntry<TKey, TValue>> split =
      Spliterators.spliteratorUnknownSize(
          this,
          Spliterator.IMMUTABLE
              | Spliterator.DISTINCT
              | Spliterator.NONNULL
              | Spliterator.ORDERED
              | Spliterator.SORTED);

  return StreamSupport.stream(split, false).onClose(this::close);
}
 
Example #29
Source File: RocksDbInstance.java    From teku with Apache License 2.0 5 votes vote down vote up
@Override
@MustBeClosed
public <K extends Comparable<K>, V> Stream<ColumnEntry<K, V>> stream(
    final RocksDbColumn<K, V> column, final K from, final K to) {
  assertOpen();
  return createStream(
      column,
      iter -> iter.seek(column.getKeySerializer().serialize(from)),
      key -> key.compareTo(to) <= 0);
}
 
Example #30
Source File: RocksDbInstance.java    From teku with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("MustBeClosedChecker")
@MustBeClosed
private <K, V> Stream<ColumnEntry<K, V>> createStream(
    RocksDbColumn<K, V> column,
    Consumer<RocksIterator> setupIterator,
    Predicate<K> continueTest) {
  final ColumnFamilyHandle handle = columnHandles.get(column);
  final RocksIterator rocksDbIterator = db.newIterator(handle);
  setupIterator.accept(rocksDbIterator);
  return RocksDbIterator.create(column, rocksDbIterator, continueTest, closed::get).toStream();
}