joerghoh commented on code in PR #3004:
URL: https://github.com/apache/jackrabbit-oak/pull/3004#discussion_r3530788304


##########
oak-segment-remote/src/test/java/org/apache/jackrabbit/oak/segment/remote/persistentcache/PersistentDiskCacheCounterTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.jackrabbit.oak.segment.remote.persistentcache;
+
+import org.apache.jackrabbit.oak.stats.StatisticsProvider;
+import org.awaitility.Awaitility;
+import org.junit.After;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class PersistentDiskCacheCounterTest {
+
+    @Rule
+    public TemporaryFolder temporaryFolder = new TemporaryFolder(new 
File("target"));
+
+    private PersistentDiskCache cache;
+
+    @After
+    public void tearDown() {
+        if (cache != null) {
+            cache.close();
+            cache = null;
+        }
+    }
+
+    @Test
+    public void testStartupInitializesCountersFromExistingFiles() throws 
Exception {
+        File cacheFolder = temporaryFolder.newFolder();
+
+        for (int size : new int[]{100, 200, 300}) {
+            File f = new File(cacheFolder, UUID.randomUUID().toString());
+            try (FileOutputStream fos = new FileOutputStream(f)) {
+                fos.write(new byte[size]);
+            }
+        }
+
+        cache = new PersistentDiskCache(cacheFolder, 10 * 1024, new 
DiskCacheIOMonitor(StatisticsProvider.NOOP));
+
+        assertEquals(3, cache.getCacheStats().getElementCount());
+        assertEquals(600, cache.getCacheStats().estimateCurrentWeight());
+    }
+
+    @Test
+    public void testStartupExcludesTempFiles() throws Exception {
+        File cacheFolder = temporaryFolder.newFolder();
+
+        File segment = new File(cacheFolder, UUID.randomUUID().toString());
+        try (FileOutputStream fos = new FileOutputStream(segment)) {
+            fos.write(new byte[100]);
+        }
+
+        // One temp file (.part) that must NOT be counted
+        File temp = new File(cacheFolder, UUID.randomUUID().toString() + 
System.nanoTime() + ".part");

Review Comment:
   can you reuse the constant ``TEMP_FILE_SUFFIX``  in PersistentDiskCache?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to