|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 Eclipse RDF4J contributors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Distribution License v1.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: BSD-3-Clause |
| 10 | + *******************************************************************************/ |
| 11 | +package org.eclipse.rdf4j.sail.nativerdf; |
| 12 | + |
| 13 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 14 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 15 | + |
| 16 | +import java.io.File; |
| 17 | + |
| 18 | +import org.junit.jupiter.api.AfterEach; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.junit.jupiter.api.io.TempDir; |
| 21 | + |
| 22 | +/** |
| 23 | + * Verifies that the implementation used for the transaction status file can be controlled via a system property. |
| 24 | + */ |
| 25 | +public class MemoryMappedTxnStatusFileConfigTest { |
| 26 | + |
| 27 | + private static final String MEMORY_MAPPED_ENABLED_PROP = "org.eclipse.rdf4j.sail.nativerdf.MemoryMappedTxnStatusFile.enabled"; |
| 28 | + |
| 29 | + @TempDir |
| 30 | + File dataDir; |
| 31 | + |
| 32 | + @AfterEach |
| 33 | + public void clearProperty() { |
| 34 | + System.clearProperty(MEMORY_MAPPED_ENABLED_PROP); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + public void defaultUsesNioTxnStatusFile() throws Exception { |
| 39 | + TripleStore tripleStore = new TripleStore(dataDir, "spoc"); |
| 40 | + try { |
| 41 | + tripleStore.startTransaction(); |
| 42 | + tripleStore.storeTriple(1, 2, 3, 4); |
| 43 | + tripleStore.commit(); |
| 44 | + } finally { |
| 45 | + tripleStore.close(); |
| 46 | + } |
| 47 | + |
| 48 | + File txnStatusFile = new File(dataDir, TxnStatusFile.FILE_NAME); |
| 49 | + assertTrue(txnStatusFile.exists(), "Transaction status file should exist"); |
| 50 | + assertEquals(0L, txnStatusFile.length(), |
| 51 | + "Default TxnStatusFile implementation truncates the file for NONE status"); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void memoryMappedEnabledUsesFixedSizeFile() throws Exception { |
| 56 | + System.setProperty(MEMORY_MAPPED_ENABLED_PROP, "true"); |
| 57 | + |
| 58 | + TripleStore tripleStore = new TripleStore(dataDir, "spoc"); |
| 59 | + try { |
| 60 | + tripleStore.startTransaction(); |
| 61 | + tripleStore.storeTriple(1, 2, 3, 4); |
| 62 | + tripleStore.commit(); |
| 63 | + } finally { |
| 64 | + tripleStore.close(); |
| 65 | + } |
| 66 | + |
| 67 | + File txnStatusFile = new File(dataDir, TxnStatusFile.FILE_NAME); |
| 68 | + assertTrue(txnStatusFile.exists(), "Transaction status file should exist"); |
| 69 | + assertEquals(1L, txnStatusFile.length(), |
| 70 | + "Memory-mapped TxnStatusFile keeps a single status byte on disk for NONE status"); |
| 71 | + } |
| 72 | +} |
0 commit comments