org.junit.rules.TemporaryFolder#delete()源码实例Demo

下面列出了org.junit.rules.TemporaryFolder#delete() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: besu   文件: BlockSyncTestUtils.java
public static List<Block> firstBlocks(final int count) {
  final List<Block> result = new ArrayList<>(count);
  final TemporaryFolder temp = new TemporaryFolder();
  try {
    temp.create();
    final Path blocks = temp.newFile().toPath();
    BlockTestUtil.write1000Blocks(blocks);
    try (final RawBlockIterator iterator =
        new RawBlockIterator(
            blocks, rlp -> BlockHeader.readFrom(rlp, new MainnetBlockHeaderFunctions()))) {
      for (int i = 0; i < count; ++i) {
        result.add(iterator.next());
      }
    }
  } catch (final IOException ex) {
    throw new IllegalStateException(ex);
  } finally {
    temp.delete();
  }
  return result;
}
 
public void tearDown() {
    stop();
    TemporaryFolder tempFolder = this.getTemporaryFolder();
    if (tempFolder != null) {
        tempFolder.delete();
    }
}
 
public void tearDown() {
    stop();
    TemporaryFolder tempFolder = this.getTemporaryFolder();
    if (tempFolder != null) {
        tempFolder.delete();
    }
}
 
源代码4 项目: asciidoctorj   文件: AsciidoctorTestObserver.java
public void afterTestShutdownUnsharedTemporaryFolderInstance(@Observes After after) {
    TemporaryFolder temporaryFolder = scopedTemporaryFolder.get().getUnsharedTemporaryFolder();
    if (temporaryFolder != null) {
        temporaryFolder.delete();
        scopedTemporaryFolder.get().setUnsharedTemporaryFolder(null);
    }
}
 
源代码5 项目: asciidoctorj   文件: AsciidoctorTestObserver.java
public void afterTestClassShutdownSharedTemporaryFolderInstance(@Observes AfterClass afterClass) {
    TemporaryFolder temporaryFolder = scopedTemporaryFolder.get().getSharedTemporaryFolder();
    if (temporaryFolder != null) {
        temporaryFolder.delete();
        scopedTemporaryFolder.get().setSharedTemporaryFolder(null);
    }

}
 
@Test
public void sanitizeSymlinkedWorkingDirectory() throws IOException {
  TemporaryFolder folder = new TemporaryFolder();
  folder.create();

  // Setup up a symlink to our working directory.
  Path symlinkedRoot = folder.getRoot().toPath().resolve("symlinked-root");
  CreateSymlinksForTests.createSymLink(symlinkedRoot, tmp.getRoot());

  // Run the build, setting PWD to the above symlink.  Typically, this causes compilers to use
  // the symlinked directory, even though it's not the right project root.
  BuildTarget target = BuildTargetFactory.newInstance("//:simple#default,static");
  workspace
      .runBuckCommandWithEnvironmentOverridesAndContext(
          tmp.getRoot(),
          Optional.empty(),
          ImmutableMap.of("PWD", symlinkedRoot.toString()),
          "build",
          target.getFullyQualifiedName())
      .assertSuccess();

  // Verify that we still sanitized this path correctly.
  Path lib =
      workspace.getPath(
          BuildTargetPaths.getGenPath(
              workspace.getProjectFileSystem(), target, "%s/libsimple.a"));
  String contents = Files.asByteSource(lib.toFile()).asCharSource(Charsets.ISO_8859_1).read();
  assertFalse(lib.toString(), contents.contains(tmp.getRoot().toString()));
  assertFalse(lib.toString(), contents.contains(symlinkedRoot.toString()));

  folder.delete();
}
 
源代码7 项目: besu   文件: BlockchainSetupUtil.java
private static BlockchainSetupUtil create(
    final ChainResources chainResources,
    final ProtocolScheduleProvider protocolScheduleProvider,
    final ProtocolContextProvider protocolContextProvider,
    final EthScheduler scheduler) {
  final TemporaryFolder temp = new TemporaryFolder();
  try {
    temp.create();
    final String genesisJson = Resources.toString(chainResources.getGenesisURL(), Charsets.UTF_8);

    final GenesisConfigFile genesisConfigFile = GenesisConfigFile.fromConfig(genesisJson);
    final ProtocolSchedule protocolSchedule = protocolScheduleProvider.get(genesisConfigFile);

    final GenesisState genesisState = GenesisState.fromJson(genesisJson, protocolSchedule);
    final MutableBlockchain blockchain = createInMemoryBlockchain(genesisState.getBlock());
    final WorldStateArchive worldArchive = createInMemoryWorldStateArchive();
    final TransactionPool transactionPool = mock(TransactionPool.class);

    genesisState.writeStateTo(worldArchive.getMutable());
    final ProtocolContext protocolContext = protocolContextProvider.get(blockchain, worldArchive);

    final Path blocksPath = Path.of(chainResources.getBlocksURL().toURI());
    final List<Block> blocks = new ArrayList<>();
    final BlockHeaderFunctions blockHeaderFunctions =
        ScheduleBasedBlockHeaderFunctions.create(protocolSchedule);
    try (final RawBlockIterator iterator =
        new RawBlockIterator(
            blocksPath, rlp -> BlockHeader.readFrom(rlp, blockHeaderFunctions))) {
      while (iterator.hasNext()) {
        blocks.add(iterator.next());
      }
    }
    return new BlockchainSetupUtil(
        genesisState,
        blockchain,
        protocolContext,
        protocolSchedule,
        worldArchive,
        transactionPool,
        blocks,
        scheduler);
  } catch (final IOException | URISyntaxException ex) {
    throw new IllegalStateException(ex);
  } finally {
    temp.delete();
  }
}
 
源代码8 项目: Flink-CEPplus   文件: TaskStateManagerImplTest.java
/**
 * This tests if the {@link TaskStateManager} properly returns the the subtask local state dir from the
 * corresponding {@link TaskLocalStateStoreImpl}.
 */
@Test
public void testForwardingSubtaskLocalStateBaseDirFromLocalStateStore() throws IOException {
	JobID jobID = new JobID(42L, 43L);
	AllocationID allocationID = new AllocationID(4711L, 23L);
	JobVertexID jobVertexID = new JobVertexID(12L, 34L);
	ExecutionAttemptID executionAttemptID = new ExecutionAttemptID(23L, 24L);
	TestCheckpointResponder checkpointResponderMock = new TestCheckpointResponder();

	Executor directExecutor = Executors.directExecutor();

	TemporaryFolder tmpFolder = new TemporaryFolder();

	try {
		tmpFolder.create();

		File[] allocBaseDirs = new File[]{tmpFolder.newFolder(), tmpFolder.newFolder(), tmpFolder.newFolder()};

		LocalRecoveryDirectoryProviderImpl directoryProvider =
			new LocalRecoveryDirectoryProviderImpl(allocBaseDirs, jobID, jobVertexID, 0);

		LocalRecoveryConfig localRecoveryConfig =
			new LocalRecoveryConfig(true, directoryProvider);

		TaskLocalStateStore taskLocalStateStore =
			new TaskLocalStateStoreImpl(jobID, allocationID, jobVertexID, 13, localRecoveryConfig, directExecutor);

		TaskStateManager taskStateManager = taskStateManager(
			jobID,
			executionAttemptID,
			checkpointResponderMock,
			null,
			taskLocalStateStore);

		LocalRecoveryConfig localRecoveryConfFromTaskLocalStateStore =
			taskLocalStateStore.getLocalRecoveryConfig();

		LocalRecoveryConfig localRecoveryConfFromTaskStateManager =
			taskStateManager.createLocalRecoveryConfig();


		for (int i = 0; i < 10; ++i) {
			Assert.assertEquals(allocBaseDirs[i % allocBaseDirs.length],
				localRecoveryConfFromTaskLocalStateStore.getLocalStateDirectoryProvider().allocationBaseDirectory(i));
			Assert.assertEquals(allocBaseDirs[i % allocBaseDirs.length],
				localRecoveryConfFromTaskStateManager.getLocalStateDirectoryProvider().allocationBaseDirectory(i));
		}

		Assert.assertEquals(
			localRecoveryConfFromTaskLocalStateStore.isLocalRecoveryEnabled(),
			localRecoveryConfFromTaskStateManager.isLocalRecoveryEnabled());
	} finally {
		tmpFolder.delete();
	}
}
 
源代码9 项目: flink   文件: TaskStateManagerImplTest.java
/**
 * This tests if the {@link TaskStateManager} properly returns the the subtask local state dir from the
 * corresponding {@link TaskLocalStateStoreImpl}.
 */
@Test
public void testForwardingSubtaskLocalStateBaseDirFromLocalStateStore() throws IOException {
	JobID jobID = new JobID(42L, 43L);
	AllocationID allocationID = new AllocationID(4711L, 23L);
	JobVertexID jobVertexID = new JobVertexID(12L, 34L);
	ExecutionAttemptID executionAttemptID = new ExecutionAttemptID(23L, 24L);
	TestCheckpointResponder checkpointResponderMock = new TestCheckpointResponder();

	Executor directExecutor = Executors.directExecutor();

	TemporaryFolder tmpFolder = new TemporaryFolder();

	try {
		tmpFolder.create();

		File[] allocBaseDirs = new File[]{tmpFolder.newFolder(), tmpFolder.newFolder(), tmpFolder.newFolder()};

		LocalRecoveryDirectoryProviderImpl directoryProvider =
			new LocalRecoveryDirectoryProviderImpl(allocBaseDirs, jobID, jobVertexID, 0);

		LocalRecoveryConfig localRecoveryConfig =
			new LocalRecoveryConfig(true, directoryProvider);

		TaskLocalStateStore taskLocalStateStore =
			new TaskLocalStateStoreImpl(jobID, allocationID, jobVertexID, 13, localRecoveryConfig, directExecutor);

		TaskStateManager taskStateManager = taskStateManager(
			jobID,
			executionAttemptID,
			checkpointResponderMock,
			null,
			taskLocalStateStore);

		LocalRecoveryConfig localRecoveryConfFromTaskLocalStateStore =
			taskLocalStateStore.getLocalRecoveryConfig();

		LocalRecoveryConfig localRecoveryConfFromTaskStateManager =
			taskStateManager.createLocalRecoveryConfig();


		for (int i = 0; i < 10; ++i) {
			Assert.assertEquals(allocBaseDirs[i % allocBaseDirs.length],
				localRecoveryConfFromTaskLocalStateStore.getLocalStateDirectoryProvider().allocationBaseDirectory(i));
			Assert.assertEquals(allocBaseDirs[i % allocBaseDirs.length],
				localRecoveryConfFromTaskStateManager.getLocalStateDirectoryProvider().allocationBaseDirectory(i));
		}

		Assert.assertEquals(
			localRecoveryConfFromTaskLocalStateStore.isLocalRecoveryEnabled(),
			localRecoveryConfFromTaskStateManager.isLocalRecoveryEnabled());
	} finally {
		tmpFolder.delete();
	}
}
 
源代码10 项目: DataflowTemplates   文件: ErrorConvertersTest.java
@Test
@Category(NeedsRunner.class)
public void testErrorLogs() throws IOException {
  TupleTag<String> errorTag = new TupleTag<String>("errors") {};
  TupleTag<String> goodTag = new TupleTag<String>("good") {};

  TemporaryFolder tmpFolder = new TemporaryFolder();
  tmpFolder.create();

  pipeline
      .apply(Create.of("Hello", "World", "Colin"))
      .apply(
          ParDo.of(
              new DoFn<String, String>() {
                @ProcessElement
                public void processElement(ProcessContext c) {
                  if (c.element().equals("Hello")) {
                    c.output(c.element());
                  } else {
                    c.output(errorTag, c.element());
                  }
                }
              })
              .withOutputTags(goodTag, TupleTagList.of(errorTag)))
      .apply(
          ErrorConverters.LogErrors.newBuilder()
              .setErrorWritePath(
                  tmpFolder.getRoot().getAbsolutePath() + "errors.txt")
              .setErrorTag(errorTag)
              .build());

  pipeline.run();

  // Read in tempfile data
  File file = new File(tmpFolder.getRoot().getAbsolutePath() + "errors.txt-00000-of-00001");
  String fileContents = Files.toString(file, Charsets.UTF_8);
  tmpFolder.delete();

  // Get the unique expected & received lines of text
  HashSet<String> expected = new HashSet<>();
  Collections.addAll(expected, "World", "Colin");

  HashSet<String> result = new HashSet<>();
  Collections.addAll(result, fileContents.split("\n"));

  assertThat(result).isEqualTo(expected);
}
 
源代码11 项目: DataflowTemplates   文件: ErrorConvertersTest.java
@Test
@Category(NeedsRunner.class)
public void testErrorLogs() throws IOException {
  TupleTag<String> errorTag = new TupleTag<String>("errors") {};
  TupleTag<String> goodTag = new TupleTag<String>("good") {};

  TemporaryFolder tmpFolder = new TemporaryFolder();
  tmpFolder.create();

  pipeline
      .apply(Create.of("Hello", "World", "Colin"))
      .apply(
          ParDo.of(
                  new DoFn<String, String>() {
                    @ProcessElement
                    public void processElement(ProcessContext c) {
                      if (c.element().equals("Hello")) {
                        c.output(c.element());
                      } else {
                        c.output(errorTag, c.element());
                      }
                    }
                  })
              .withOutputTags(goodTag, TupleTagList.of(errorTag)))
      .apply(
          ErrorConverters.LogErrors.newBuilder()
              .setErrorWritePath(
                  StaticValueProvider.of(tmpFolder.getRoot().getAbsolutePath() + "errors.txt"))
              .setErrorTag(errorTag)
              .build());

  pipeline.run();

  // Read in tempfile data
  File file = new File(tmpFolder.getRoot().getAbsolutePath() + "errors.txt-00000-of-00001");
  String fileContents = Files.toString(file, Charsets.UTF_8);
  tmpFolder.delete();

  // Get the unique expected & received lines of text
  HashSet<String> expected = new HashSet<>();
  Collections.addAll(expected, "World", "Colin");

  HashSet<String> result = new HashSet<>();
  Collections.addAll(result, fileContents.split("\n"));

  Assert.assertEquals(expected, result);
}
 
源代码12 项目: flink   文件: TaskStateManagerImplTest.java
/**
 * This tests if the {@link TaskStateManager} properly returns the the subtask local state dir from the
 * corresponding {@link TaskLocalStateStoreImpl}.
 */
@Test
public void testForwardingSubtaskLocalStateBaseDirFromLocalStateStore() throws IOException {
	JobID jobID = new JobID(42L, 43L);
	AllocationID allocationID = new AllocationID(4711L, 23L);
	JobVertexID jobVertexID = new JobVertexID(12L, 34L);
	ExecutionAttemptID executionAttemptID = new ExecutionAttemptID(23L, 24L);
	TestCheckpointResponder checkpointResponderMock = new TestCheckpointResponder();

	Executor directExecutor = Executors.directExecutor();

	TemporaryFolder tmpFolder = new TemporaryFolder();

	try {
		tmpFolder.create();

		File[] allocBaseDirs = new File[]{tmpFolder.newFolder(), tmpFolder.newFolder(), tmpFolder.newFolder()};

		LocalRecoveryDirectoryProviderImpl directoryProvider =
			new LocalRecoveryDirectoryProviderImpl(allocBaseDirs, jobID, jobVertexID, 0);

		LocalRecoveryConfig localRecoveryConfig =
			new LocalRecoveryConfig(true, directoryProvider);

		TaskLocalStateStore taskLocalStateStore =
			new TaskLocalStateStoreImpl(jobID, allocationID, jobVertexID, 13, localRecoveryConfig, directExecutor);

		TaskStateManager taskStateManager = taskStateManager(
			jobID,
			executionAttemptID,
			checkpointResponderMock,
			null,
			taskLocalStateStore);

		LocalRecoveryConfig localRecoveryConfFromTaskLocalStateStore =
			taskLocalStateStore.getLocalRecoveryConfig();

		LocalRecoveryConfig localRecoveryConfFromTaskStateManager =
			taskStateManager.createLocalRecoveryConfig();


		for (int i = 0; i < 10; ++i) {
			Assert.assertEquals(allocBaseDirs[i % allocBaseDirs.length],
				localRecoveryConfFromTaskLocalStateStore.getLocalStateDirectoryProvider().allocationBaseDirectory(i));
			Assert.assertEquals(allocBaseDirs[i % allocBaseDirs.length],
				localRecoveryConfFromTaskStateManager.getLocalStateDirectoryProvider().allocationBaseDirectory(i));
		}

		Assert.assertEquals(
			localRecoveryConfFromTaskLocalStateStore.isLocalRecoveryEnabled(),
			localRecoveryConfFromTaskStateManager.isLocalRecoveryEnabled());
	} finally {
		tmpFolder.delete();
	}
}