Java Code Examples for org.assertj.core.util.Files#newTemporaryFolder()

The following examples show how to use org.assertj.core.util.Files#newTemporaryFolder() . 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: TestGeneratorFactoryTest.java    From RDFUnit with Apache License 2.0 6 votes vote down vote up
@Test
public void testTagAndCache() {
    File directory = Files.newTemporaryFolder();
    directory.deleteOnExit();

    RdfUnitTestGenerator g = new GenerateAndCacheRdfUnitTestGenerator(
            new TagRdfUnitTestGenerator(rdfUnit.getAutoGenerators()),
            directory.getAbsolutePath());

    assertThat(directory.listFiles().length == 0).isTrue();
    assertThat(g.generate(schemaSourceOwl))
            .isNotEmpty();
    assertThat(directory.listFiles().length == 1).isTrue();

    // read the cached data
    assertThat(new CacheTestGenerator(directory.getAbsolutePath())
    .generate(schemaSourceOwl))
            .isNotEmpty();
}
 
Example 2
Source File: TransactionsPerSecondBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Setup(Level.Iteration)
public void beforeClass() {
	if (connection != null) {
		connection.close();
		connection = null;
	}
	i = 0;
	file = Files.newTemporaryFolder();

	NativeStore sail = new NativeStore(file, "spoc,ospc,psoc");
	sail.setForceSync(false);
	repository = new SailRepository(sail);
	connection = repository.getConnection();

	System.gc();

}
 
Example 3
Source File: TransactionsPerSecondForceSyncBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Setup(Level.Iteration)
public void beforeClass() {
	if (connection != null) {
		connection.close();
		connection = null;
	}
	i = 0;
	file = Files.newTemporaryFolder();

	NativeStore sail = new NativeStore(file, "spoc,ospc,psoc");
	sail.setForceSync(true);
	repository = new SailRepository(sail);
	connection = repository.getConnection();

	System.gc();

}
 
Example 4
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Benchmark
public void nativeStoreShaclSnapshotWithoutSerializableValidation(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		((ShaclSail) repository.getSail()).setSerializableValidation(false);

		runBenchmark(IsolationLevels.SNAPSHOT, repository, true, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 5
Source File: DeadlockTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test() throws IOException {

	for (int i = 0; i < 10; i++) {

		String shaclPath = "complexBenchmark/";

		File dataDir = Files.newTemporaryFolder();
		dataDir.deleteOnExit();

		ShaclSail shaclSail = new ShaclSail(new NativeStore(dataDir));
		SailRepository shaclRepository = new SailRepository(shaclSail);
		shaclRepository.init();

		shaclSail.setParallelValidation(true);

		Utils.loadShapeData(shaclRepository, shaclPath + "shacl.ttl");

		try (SailRepositoryConnection connection = shaclRepository.getConnection()) {

			connection.begin(IsolationLevels.SNAPSHOT);
			connection
					.prepareUpdate(IOUtil.readString(
							DeadlockTest.class.getClassLoader().getResourceAsStream(shaclPath + "transaction1.qr")))
					.execute();
			connection.commit();

			connection.begin(IsolationLevels.SNAPSHOT);
			connection
					.prepareUpdate(IOUtil.readString(
							DeadlockTest.class.getClassLoader().getResourceAsStream(shaclPath + "transaction2.qr")))
					.execute();
			connection.commit();
		}
	}
}
 
Example 6
Source File: MemInferencingTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
	public void testPersistence() {
		File datadir = Files.newTemporaryFolder();

		SchemaCachingRDFSInferencer sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
		SailRepository repo = new SailRepository(sailStack);
		repo.initialize();
		ValueFactory vf = repo.getValueFactory();

		IRI s1 = vf.createIRI("foo:s1");
		IRI c2 = vf.createIRI("foo:c2");
		IRI c1 = vf.createIRI("foo:c1");

		try (RepositoryConnection conn = repo.getConnection()) {
			conn.begin();
			conn.add(s1, RDF.TYPE, c1);
			conn.add(c1, RDFS.SUBCLASSOF, c2);
			conn.commit();
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
		repo.shutDown();

		// re-init
//		sailStack = new SchemaCachingRDFSInferencer(new MemoryStore(datadir), true);
//		repo = new SailRepository(sailStack);
		repo.initialize();

		try (RepositoryConnection conn = repo.getConnection()) {
			assertTrue(conn.hasStatement(s1, RDF.TYPE, c2, true));
		}
	}
 
Example 7
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public void nativeStoreShaclSnapshot(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		runBenchmark(IsolationLevels.SNAPSHOT, repository, true, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 8
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public void nativeStoreShaclSerializableNotParallel(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		runBenchmark(IsolationLevels.SERIALIZABLE, repository, false, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 9
Source File: ParallelBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Benchmark
public void nativeStoreShaclSerializable(Blackhole blackhole) throws Exception {
	File file = Files.newTemporaryFolder();

	try {
		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"), "shaclDatatype.ttl"));
		runBenchmark(IsolationLevels.SERIALIZABLE, repository, true, false, blackhole);

	} finally {
		FileUtils.deleteDirectory(file);
	}

}
 
Example 10
Source File: NativeStoreBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Benchmark
public void shaclParallelNativeStore() throws IOException {

	File file = Files.newTemporaryFolder();

	ShaclSail shaclSail = new ShaclSail(new NativeStore(file, "spoc,ospc,psoc"));

	// significantly reduce required memory
	shaclSail.setCacheSelectNodes(false);

	// run validation in parallel as much as possible,
	// this can be disabled to reduce memory load further
	shaclSail.setParallelValidation(true);

	SailRepository sailRepository = new SailRepository(shaclSail);
	sailRepository.init();
	shaclSail.disableValidation();

	try (SailRepositoryConnection connection = sailRepository.getConnection()) {

		connection.begin(IsolationLevels.NONE);
		try (InputStream inputStream = getFile("complexBenchmark/shacl.ttl")) {
			connection.add(inputStream, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH);
		}
		connection.commit();

		connection.begin(IsolationLevels.NONE);

		try (InputStream inputStream = new BufferedInputStream(getFile("complexBenchmark/generated.ttl"))) {
			connection.add(inputStream, "", RDFFormat.TURTLE);
		}
		connection.commit();

	}
	shaclSail.enableValidation();

	try (SailRepositoryConnection connection = sailRepository.getConnection()) {

		connection.begin(IsolationLevels.NONE);
		ValidationReport revalidate = ((ShaclSailConnection) connection.getSailConnection()).revalidate();
		connection.commit();

		if (!revalidate.conforms()) {
			Rio.write(revalidate.asModel(), System.out, RDFFormat.TURTLE);
		}

	}

	sailRepository.shutDown();

	FileUtils.deleteDirectory(file);

}
 
Example 11
Source File: MultithreadedNativeStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Before
public void before() {
	file = Files.newTemporaryFolder();
}
 
Example 12
Source File: LongMultithreadedTransactions.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Before
public void before() {
	file = Files.newTemporaryFolder();
}
 
Example 13
Source File: NativeStoreBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Benchmark
public void shaclNativeStore() throws IOException {

	File file = Files.newTemporaryFolder();

	ShaclSail shaclSail = new ShaclSail(new NativeStore(file, "spoc,ospc,psoc"));

	// significantly reduce required memory
	shaclSail.setCacheSelectNodes(false);

	// run validation in parallel as much as possible,
	// this can be disabled to reduce memory load further
	shaclSail.setParallelValidation(false);

	SailRepository sailRepository = new SailRepository(shaclSail);
	sailRepository.init();
	shaclSail.disableValidation();

	try (SailRepositoryConnection connection = sailRepository.getConnection()) {

		connection.begin(IsolationLevels.NONE);
		try (InputStream inputStream = getFile("complexBenchmark/shacl.ttl")) {
			connection.add(inputStream, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH);
		}
		connection.commit();

		connection.begin(IsolationLevels.NONE);

		try (InputStream inputStream = new BufferedInputStream(getFile("complexBenchmark/generated.ttl"))) {
			connection.add(inputStream, "", RDFFormat.TURTLE);
		}
		connection.commit();

	}
	shaclSail.enableValidation();

	try (SailRepositoryConnection connection = sailRepository.getConnection()) {

		connection.begin(IsolationLevels.NONE);
		ValidationReport revalidate = ((ShaclSailConnection) connection.getSailConnection()).revalidate();
		connection.commit();

		if (!revalidate.conforms()) {
			Rio.write(revalidate.asModel(), System.out, RDFFormat.TURTLE);
		}

	}

	sailRepository.shutDown();

	FileUtils.deleteDirectory(file);

}
 
Example 14
Source File: ComplexLargeBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Benchmark
public void noPreloadingRevalidateNativeStore() throws IOException {
	File file = Files.newTemporaryFolder();

	try {

		SailRepository repository = new SailRepository(
				Utils.getInitializedShaclSail(new NativeStore(file, "spoc,ospc,psoc"),
						"complexBenchmark/shacl.ttl"));

		((ShaclSail) repository.getSail()).setParallelValidation(true);
		((ShaclSail) repository.getSail()).setCacheSelectNodes(true);

		((ShaclSail) repository.getSail()).disableValidation();

		try (SailRepositoryConnection connection = repository.getConnection()) {
			connection.begin(IsolationLevels.NONE);
			try (InputStream resourceAsStream = getData()) {
				connection.add(resourceAsStream, "", RDFFormat.TURTLE);
			}
			connection.commit();
		}

		((ShaclSail) repository.getSail()).enableValidation();

		try (SailRepositoryConnection connection = repository.getConnection()) {
			connection.begin(IsolationLevels.NONE);
			((ShaclSailConnection) connection.getSailConnection()).revalidate();
			connection.commit();
		}

		repository.shutDown();

	} catch (IOException e) {
		throw new RuntimeException(e);
	} finally {
		FileUtils.deleteDirectory(file);

	}

}
 
Example 15
Source File: QueryBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Setup(Level.Trial)
public void beforeClass() throws IOException {

	file = Files.newTemporaryFolder();

	repository = new SailRepository(new NativeStore(file, "spoc,ospc,psoc"));

	try (SailRepositoryConnection connection = repository.getConnection()) {
		connection.begin(IsolationLevels.NONE);
		connection.add(getResourceAsStream("benchmarkFiles/datagovbe-valid.ttl"), "", RDFFormat.TURTLE);
		connection.commit();
	}

	try (SailRepositoryConnection connection = repository.getConnection()) {

		statementList = Iterations.asList(connection.getStatements(null, RDF.TYPE, null, false));
	}

	System.gc();

}
 
Example 16
Source File: HashFileBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Setup(Level.Trial)
public void beforeClass() throws IOException {

	tempFolder = Files.newTemporaryFolder();

	File file = File.createTempFile("hashfile", "hash", tempFolder);

	hashFile = new HashFile(file, false, (int) (COUNT / .75f) + 1);
	Random random = new Random(RANDOM_SEED);

	hashes = new ArrayList<>();

	for (int i = 0; i < COUNT; i++) {
		int hash = random.nextInt();
		hashes.add(hash);
		hashFile.storeID(hash, i);
	}

	hashFile.sync(true);

	System.gc();

}
 
Example 17
Source File: DataFileBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Setup(Level.Trial)
public void beforeClass() throws IOException {

	tempFolder = Files.newTemporaryFolder();

	File file = File.createTempFile("hashfile", "hash", tempFolder);

	dataFile = new DataFile(file);
	Random random = new Random(RANDOM_SEED);

	offsets = new ArrayList<>();

	for (int i = 0; i < COUNT; i++) {
		int length = random.nextInt(BYTES.length);
		long offset = dataFile.storeData(Arrays.copyOf(BYTES, length));
		offsets.add(offset);
	}

	dataFile.sync(true);

	System.gc();

}
 
Example 18
Source File: IDFileBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Setup(Level.Trial)
public void beforeClass() throws IOException {

	tempFolder = Files.newTemporaryFolder();

	File file = File.createTempFile("idfile", "id", tempFolder);

	idFile = new IDFile(file);

	for (int i = 0; i < COUNT * 8; i++) {
		idFile.storeOffset(i);
	}

	idFile.sync(true);

	System.gc();

}
 
Example 19
Source File: NativeStoreBenchmark.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
@Benchmark
public void nativeStore() throws IOException {

	File file = Files.newTemporaryFolder();

	NotifyingSail shaclSail = new NativeStore(file, "spoc,ospc,psoc");

	SailRepository sailRepository = new SailRepository(shaclSail);
	sailRepository.init();

	try (SailRepositoryConnection connection = sailRepository.getConnection()) {

		connection.begin(IsolationLevels.NONE);

		try (InputStream inputStream = getFile("complexBenchmark/shacl.ttl")) {
			connection.add(inputStream, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH);
		}
		connection.commit();

		connection.begin(IsolationLevels.NONE);

		try (InputStream inputStream = new BufferedInputStream(getFile("complexBenchmark/generated.ttl"))) {
			connection.add(inputStream, "", RDFFormat.TURTLE);
		}
		connection.commit();

	}

	sailRepository.shutDown();

	FileUtils.deleteDirectory(file);

}
 
Example 20
Source File: NativeStoreTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
@Test
public void testEmpty() throws IOException {

	File file = Files.newTemporaryFolder();

	SailRepository shaclSail = new SailRepository(new ShaclSail(new NativeStore(file)));
	shaclSail.init();

	shaclSail.shutDown();

	delete(file);
}