|
| 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.http.server; |
| 12 | + |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; |
| 14 | + |
| 15 | +import org.eclipse.rdf4j.http.protocol.Protocol; |
| 16 | +import org.eclipse.rdf4j.model.IRI; |
| 17 | +import org.eclipse.rdf4j.model.Model; |
| 18 | +import org.eclipse.rdf4j.model.Resource; |
| 19 | +import org.eclipse.rdf4j.model.ValueFactory; |
| 20 | +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; |
| 21 | +import org.eclipse.rdf4j.repository.Repository; |
| 22 | +import org.eclipse.rdf4j.repository.RepositoryConnection; |
| 23 | +import org.eclipse.rdf4j.repository.RepositoryException; |
| 24 | +import org.eclipse.rdf4j.repository.config.RepositoryConfig; |
| 25 | +import org.eclipse.rdf4j.repository.http.HTTPRepository; |
| 26 | +import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager; |
| 27 | +import org.eclipse.rdf4j.repository.sail.config.SailRepositoryConfig; |
| 28 | +import org.eclipse.rdf4j.sail.config.AbstractSailImplConfig; |
| 29 | +import org.junit.jupiter.api.AfterAll; |
| 30 | +import org.junit.jupiter.api.BeforeAll; |
| 31 | +import org.junit.jupiter.api.Test; |
| 32 | + |
| 33 | +/** |
| 34 | + * Jetty-based integration test that reproduces a user report: Creating an LMDB repository with an invalid triple index |
| 35 | + * (e.g., "cposc") then attempting to delete it via HTTP fails. |
| 36 | + * |
| 37 | + * Expected behavior: either reject creation upfront or allow deletion. This test asserts deletion succeeds; it |
| 38 | + * currently fails, exposing the bug. |
| 39 | + */ |
| 40 | +public class LmdbInvalidIndexDeletionIT { |
| 41 | + |
| 42 | + private static TestServer server; |
| 43 | + |
| 44 | + @BeforeAll |
| 45 | + public static void startServer() throws Exception { |
| 46 | + server = new TestServer(); |
| 47 | + try { |
| 48 | + server.start(); |
| 49 | + } catch (Exception e) { |
| 50 | + server.stop(); |
| 51 | + throw e; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @AfterAll |
| 56 | + public static void stopServer() throws Exception { |
| 57 | + server.stop(); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + void deletionSucceedsAfterInvalidLmdbInit() throws Exception { |
| 62 | + String id = "badlmdb-server"; |
| 63 | + |
| 64 | + // Build a minimal LMDB Sail config without depending on LMDB classes |
| 65 | + // by exporting with the LMDB sail type and the tripleIndexes property. |
| 66 | + class GenericLmdbConfig extends AbstractSailImplConfig { |
| 67 | + private final String tripleIndexes; |
| 68 | + |
| 69 | + GenericLmdbConfig(String type, String tripleIndexes) { |
| 70 | + super(type); |
| 71 | + this.tripleIndexes = tripleIndexes; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public Resource export(Model m) { |
| 76 | + Resource node = super.export(m); |
| 77 | + ValueFactory vf = SimpleValueFactory.getInstance(); |
| 78 | + IRI tripleIdx = vf.createIRI("http://rdf4j.org/config/sail/lmdb#tripleIndexes"); |
| 79 | + m.add(node, tripleIdx, vf.createLiteral(tripleIndexes)); |
| 80 | + return node; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + GenericLmdbConfig lmdbConfig = new GenericLmdbConfig("rdf4j:LmdbStore", "cposc"); |
| 85 | + RepositoryConfig repoConfig = new RepositoryConfig(id, new SailRepositoryConfig(lmdbConfig)); |
| 86 | + |
| 87 | + RemoteRepositoryManager manager = RemoteRepositoryManager.getInstance(TestServer.SERVER_URL); |
| 88 | + try { |
| 89 | + try { |
| 90 | + // Create config on server (does not initialize the underlying store yet) |
| 91 | + manager.addRepositoryConfig(repoConfig); |
| 92 | + } catch (Exception ignored) { |
| 93 | + } |
| 94 | + |
| 95 | + // Trigger initialization by opening a connection; expected to fail due to invalid index |
| 96 | + Repository httpRepo = new HTTPRepository( |
| 97 | + Protocol.getRepositoryLocation(TestServer.SERVER_URL, id)); |
| 98 | + try (RepositoryConnection conn = httpRepo.getConnection()) { |
| 99 | + // attempt a trivial call to ensure init |
| 100 | + conn.size(); |
| 101 | + } catch (RepositoryException expected) { |
| 102 | + // initialization fails as LMDB rejects invalid index spec |
| 103 | + } |
| 104 | + |
| 105 | + // Now attempt to delete the repository; expected to succeed |
| 106 | + boolean removed = manager.removeRepository(id); |
| 107 | + assertThat(removed).isTrue(); |
| 108 | + } finally { |
| 109 | + // best-effort cleanup if assertion failed |
| 110 | + try { |
| 111 | + manager.removeRepository(id); |
| 112 | + } catch (Exception ignore) { |
| 113 | + } finally { |
| 114 | + manager.shutDown(); |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | +} |
0 commit comments