LmdbStoreTmpDatadirTest.java

/*******************************************************************************
 * Copyright (c) 2021 Eclipse RDF4J contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Distribution License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *******************************************************************************/
package org.eclipse.rdf4j.sail.lmdb;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class LmdbStoreTmpDatadirTest {

	@Test
	public void testNoTmpDatadir(@TempDir File dataDir) {
		LmdbStore store = new LmdbStore(dataDir);

		store.init();
		assertTrue("Data dir not set correctly", dataDir.equals(store.getDataDir()));

		store.shutDown();
		assertTrue("Data dir does not exist anymore", dataDir.exists());
	}

	@Test
	public void testTmpDatadir() {
		LmdbStore store = new LmdbStore();
		store.init();
		File dataDir = store.getDataDir();
		assertTrue("Temp data dir not created", dataDir != null && dataDir.exists());

		store.shutDown();
		assertFalse("Temp data dir still exists", dataDir.exists());
	}

	@Test
	public void testTmpDatadirReinit() {
		LmdbStore store = new LmdbStore();
		store.init();
		File dataDir1 = store.getDataDir();
		store.shutDown();

		store.init();
		File dataDir2 = store.getDataDir();
		store.shutDown();
		assertFalse("Temp data dirs are the same", dataDir1.equals(dataDir2));
	}

	@Test
	public void testDatadirMix(@TempDir File dataDir) {
		LmdbStore store = new LmdbStore(dataDir);

		store.init();
		store.shutDown();

		store.setDataDir(null);
		store.init();
		File tmpDataDir = store.getDataDir();
		store.shutDown();

		assertFalse("Temp data dir still exists", tmpDataDir.exists());
		assertTrue("Data dir does not exist anymore", dataDir.exists());
	}
}