This is an automated email from the ASF dual-hosted git repository.

ndipiazza pushed a commit to branch TIKA-4576-add-fetcher-config-store-interface
in repository https://gitbox.apache.org/repos/asf/tika.git

commit 70dfff7224ff8482c7085030c3930867bf6cb548
Author: Nicholas DiPiazza <[email protected]>
AuthorDate: Tue Dec 16 13:29:32 2025 -0600

    TIKA-4576
    Create pluggable storage interface for Fetcher components with in-memory 
implementation
---
 .../tika/pipes/core/config/ConfigStoreTest.java    | 92 ++++++++++++++++++++++
 .../tika/pipes/core/config/LoggingConfigStore.java | 75 ++++++++++++++++++
 2 files changed, 167 insertions(+)

diff --git 
a/tika-pipes/tika-pipes-core/src/test/java/org/apache/tika/pipes/core/config/ConfigStoreTest.java
 
b/tika-pipes/tika-pipes-core/src/test/java/org/apache/tika/pipes/core/config/ConfigStoreTest.java
new file mode 100644
index 000000000..c1ce08601
--- /dev/null
+++ 
b/tika-pipes/tika-pipes-core/src/test/java/org/apache/tika/pipes/core/config/ConfigStoreTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.pipes.core.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+import org.apache.tika.plugins.ExtensionConfig;
+
+public class ConfigStoreTest {
+
+    @Test
+    public void testInMemoryConfigStore() {
+        ConfigStore store = new InMemoryConfigStore();
+        
+        ExtensionConfig config1 = new ExtensionConfig("id1", "type1", 
"{\"key\":\"value\"}");
+        ExtensionConfig config2 = new ExtensionConfig("id2", "type2", 
"{\"key2\":\"value2\"}");
+        
+        // Test put and get
+        store.put("id1", config1);
+        store.put("id2", config2);
+        
+        assertNotNull(store.get("id1"));
+        assertEquals("id1", store.get("id1").id());
+        assertEquals("type1", store.get("id1").name());
+        
+        assertNotNull(store.get("id2"));
+        assertEquals("id2", store.get("id2").id());
+        
+        // Test containsKey
+        assertTrue(store.containsKey("id1"));
+        assertTrue(store.containsKey("id2"));
+        assertFalse(store.containsKey("id3"));
+        
+        // Test size
+        assertEquals(2, store.size());
+        
+        // Test keySet
+        assertEquals(2, store.keySet().size());
+        assertTrue(store.keySet().contains("id1"));
+        assertTrue(store.keySet().contains("id2"));
+        
+        // Test get non-existent
+        assertNull(store.get("nonexistent"));
+    }
+    
+    @Test
+    public void testConfigStoreThreadSafety() throws InterruptedException {
+        ConfigStore store = new InMemoryConfigStore();
+        int numThreads = 10;
+        int numOperationsPerThread = 100;
+        
+        Thread[] threads = new Thread[numThreads];
+        for (int i = 0; i < numThreads; i++) {
+            final int threadId = i;
+            threads[i] = new Thread(() -> {
+                for (int j = 0; j < numOperationsPerThread; j++) {
+                    String id = "thread" + threadId + "_config" + j;
+                    ExtensionConfig config = new ExtensionConfig(id, "type", 
"{}");
+                    store.put(id, config);
+                    assertNotNull(store.get(id));
+                }
+            });
+            threads[i].start();
+        }
+        
+        for (Thread thread : threads) {
+            thread.join();
+        }
+        
+        assertEquals(numThreads * numOperationsPerThread, store.size());
+    }
+}
diff --git 
a/tika-pipes/tika-pipes-core/src/test/java/org/apache/tika/pipes/core/config/LoggingConfigStore.java
 
b/tika-pipes/tika-pipes-core/src/test/java/org/apache/tika/pipes/core/config/LoggingConfigStore.java
new file mode 100644
index 000000000..57f582c68
--- /dev/null
+++ 
b/tika-pipes/tika-pipes-core/src/test/java/org/apache/tika/pipes/core/config/LoggingConfigStore.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.pipes.core.config;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tika.plugins.ExtensionConfig;
+
+/**
+ * Example custom ConfigStore implementation for demonstration purposes.
+ * This implementation logs all operations and could be extended to add
+ * persistence, caching, or other custom behavior.
+ */
+public class LoggingConfigStore implements ConfigStore {
+
+    private final Map<String, ExtensionConfig> store = new HashMap<>();
+    
+    @Override
+    public void put(String id, ExtensionConfig config) {
+        System.out.println("ConfigStore: Storing config with id=" + id);
+        synchronized (store) {
+            store.put(id, config);
+        }
+    }
+
+    @Override
+    public ExtensionConfig get(String id) {
+        synchronized (store) {
+            ExtensionConfig config = store.get(id);
+            if (config != null) {
+                System.out.println("ConfigStore: Retrieved config with id=" + 
id);
+            } else {
+                System.out.println("ConfigStore: Config not found for id=" + 
id);
+            }
+            return config;
+        }
+    }
+
+    @Override
+    public boolean containsKey(String id) {
+        synchronized (store) {
+            return store.containsKey(id);
+        }
+    }
+
+    @Override
+    public Set<String> keySet() {
+        synchronized (store) {
+            return Set.copyOf(store.keySet());
+        }
+    }
+
+    @Override
+    public int size() {
+        synchronized (store) {
+            return store.size();
+        }
+    }
+}

Reply via email to