diff --git a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactory.java b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactory.java index 28e80b78a0..0ff6a5af22 100644 --- a/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactory.java +++ b/oak-upgrade/src/main/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactory.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.HashSet; +import java.util.Map; import java.util.Properties; import java.util.concurrent.Executors; import java.util.regex.Matcher; @@ -62,11 +63,6 @@ public class S3DataStoreFactory implements BlobStoreFactory { IOUtils.closeQuietly(reader); } - for (Object key : new HashSet(props.keySet())) { - String value = props.getProperty((String) key); - props.put(key, stripValue(value)); - } - this.directory = directory; this.tempHomeDir = Files.createTempDir(); this.ignoreMissingBlobs = ignoreMissingBlobs; @@ -74,12 +70,7 @@ public class S3DataStoreFactory implements BlobStoreFactory { @Override public BlobStore create(Closer closer) throws IOException { - S3DataStore delegate = new S3DataStore(); - delegate.setProperties(props); - delegate.setPath(directory); - - PropertiesUtil.populate(delegate, Maps.fromProperties(props), false); - + S3DataStore delegate = createDS(directory, props); // Initialize a default stats provider StatisticsProvider statsProvider = new DefaultStatisticsProvider(Executors.newSingleThreadScheduledExecutor()); delegate.setStatisticsProvider(statsProvider); @@ -99,6 +90,24 @@ public class S3DataStoreFactory implements BlobStoreFactory { } } + static S3DataStore createDS(String directory, Properties props) { + Properties strippedProperties = new Properties(); + Map map = Maps.newHashMap(); + + for (Object key : new HashSet<>(props.keySet())) { + String strippedValue = stripValue(props.getProperty((String) key)); + + strippedProperties.put(key, strippedValue); + map.put((String) key, strippedValue); + } + + S3DataStore ds = new S3DataStore(); + ds.setProperties(strippedProperties); + ds.setPath(directory); + PropertiesUtil.populate(ds, map, false); + return ds; + } + private static Closeable asCloseable(final S3DataStore store) { return new Closeable() { @Override diff --git a/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactoryTest.java b/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactoryTest.java new file mode 100644 index 0000000000..12c886dfc8 --- /dev/null +++ b/oak-upgrade/src/test/java/org/apache/jackrabbit/oak/upgrade/cli/blob/S3DataStoreFactoryTest.java @@ -0,0 +1,53 @@ +/* + * 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.upgrade.cli.blob; + +import org.apache.jackrabbit.oak.blob.cloud.s3.S3DataStore; +import org.apache.jackrabbit.oak.plugins.blob.AbstractSharedCachingDataStore; +import org.junit.Test; + +import java.lang.reflect.Field; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class S3DataStoreFactoryTest { + + @Test + public void testPopulateProperties() throws NoSuchFieldException, IllegalAccessException { + Properties props = new Properties(); + props.setProperty("cacheSize", "123"); + + S3DataStore ds = S3DataStoreFactory.createDS("xyz", props); + assertEquals(123, readLong("cacheSize", AbstractSharedCachingDataStore.class, ds)); + } + + @Test + public void testStripOsgiPrefix() throws NoSuchFieldException, IllegalAccessException { + Properties props = new Properties(); + props.setProperty("cacheSize", "I\"123\""); + + S3DataStore ds = S3DataStoreFactory.createDS("xyz", props); + assertEquals(123, readLong("cacheSize", AbstractSharedCachingDataStore.class, ds)); + } + + private static long readLong(String fieldName, Class clazz, Object object) throws NoSuchFieldException, IllegalAccessException { + Field field = clazz.getDeclaredField(fieldName); + field.setAccessible(true); + return field.getLong(object); + } +}