This is an automated email from the ASF dual-hosted git repository.
heiming pushed a commit to branch tiered_storage
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/tiered_storage by this push:
new 95eb0f17a66 add connector mock
95eb0f17a66 is described below
commit 95eb0f17a66343ce3f4c15e01134a28465d7d15a
Author: HeimingZ <[email protected]>
AuthorDate: Tue May 23 16:11:36 2023 +0800
add connector mock
---
.../apache/iotdb/os/conf/ObjectStorageConfig.java | 12 ++--
.../provider/TestConfig.java} | 25 +++----
.../iotdb/os/io/aws/S3ObjectStorageConnector.java | 4 +-
.../os/io/test/TestObjectStorageConnector.java | 80 ++++++++++++++++++++++
.../apache/iotdb/os/utils/ObjectStorageType.java | 2 +
.../org/apache/iotdb/os/cache/OSFileCacheTest.java | 14 ++++
.../apache/iotdb/os/cache/OSFileChannelTest.java | 14 ++++
.../apache/iotdb/os/cache/OSInputStreamTest.java | 14 ++++
8 files changed, 141 insertions(+), 24 deletions(-)
diff --git
a/object-storage/src/main/java/org/apache/iotdb/os/conf/ObjectStorageConfig.java
b/object-storage/src/main/java/org/apache/iotdb/os/conf/ObjectStorageConfig.java
index 4f9d49d41c1..9126fb21cf6 100644
---
a/object-storage/src/main/java/org/apache/iotdb/os/conf/ObjectStorageConfig.java
+++
b/object-storage/src/main/java/org/apache/iotdb/os/conf/ObjectStorageConfig.java
@@ -20,10 +20,10 @@ package org.apache.iotdb.os.conf;
import org.apache.iotdb.os.conf.provider.AWSS3Config;
import org.apache.iotdb.os.conf.provider.OSProviderConfig;
+import org.apache.iotdb.os.conf.provider.TestConfig;
import org.apache.iotdb.os.utils.ObjectStorageType;
import java.io.File;
-import java.util.Objects;
public class ObjectStorageConfig {
private ObjectStorageType osType = ObjectStorageType.AWS_S3;
@@ -46,10 +46,12 @@ public class ObjectStorageConfig {
public void setOsType(ObjectStorageType osType) {
this.osType = osType;
- if (Objects.requireNonNull(osType) == ObjectStorageType.AWS_S3) {
- this.providerConfig = new AWSS3Config();
- } else {
- this.providerConfig = null;
+ switch (osType) {
+ case AWS_S3:
+ this.providerConfig = new AWSS3Config();
+ break;
+ default:
+ this.providerConfig = new TestConfig();
}
}
diff --git
a/object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
b/object-storage/src/main/java/org/apache/iotdb/os/conf/provider/TestConfig.java
similarity index 56%
copy from
object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
copy to
object-storage/src/main/java/org/apache/iotdb/os/conf/provider/TestConfig.java
index cb793bd366b..ac32757b0c6 100644
---
a/object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
+++
b/object-storage/src/main/java/org/apache/iotdb/os/conf/provider/TestConfig.java
@@ -16,27 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.iotdb.os.utils;
+package org.apache.iotdb.os.conf.provider;
-import org.apache.iotdb.os.conf.ObjectStorageDescriptor;
-import org.apache.iotdb.os.io.ObjectStorageConnector;
-import org.apache.iotdb.os.io.aws.S3ObjectStorageConnector;
+import java.io.File;
-public enum ObjectStorageType {
- TEST,
- AWS_S3;
+public class TestConfig extends OSProviderConfig {
+ private String testDir = "target" + File.separator + "test";
- public static ObjectStorageConnector getConnector(ObjectStorageType type) {
- switch (type) {
- case AWS_S3:
- return new S3ObjectStorageConnector();
- case TEST:
- default:
- return null;
- }
+ public String getTestDir() {
+ return testDir;
}
- public static ObjectStorageConnector getConnector() {
- return
getConnector(ObjectStorageDescriptor.getInstance().getConfig().getOsType());
+ public void setTestDir(String testDir) {
+ this.testDir = testDir;
}
}
diff --git
a/object-storage/src/main/java/org/apache/iotdb/os/io/aws/S3ObjectStorageConnector.java
b/object-storage/src/main/java/org/apache/iotdb/os/io/aws/S3ObjectStorageConnector.java
index 80753b2af2e..964dd77fcd4 100644
---
a/object-storage/src/main/java/org/apache/iotdb/os/io/aws/S3ObjectStorageConnector.java
+++
b/object-storage/src/main/java/org/apache/iotdb/os/io/aws/S3ObjectStorageConnector.java
@@ -49,9 +49,9 @@ import java.io.InputStream;
public class S3ObjectStorageConnector implements ObjectStorageConnector {
private static final String RANGE_FORMAT = "%d-%d";
- private static final AWSS3Config s3config =
+ private final AWSS3Config s3config =
(AWSS3Config)
ObjectStorageDescriptor.getInstance().getConfig().getProviderConfig();
- private static final S3Client s3Client =
+ private final S3Client s3Client =
S3Client.builder()
.region(Region.of(s3config.getEndpoint()))
.credentialsProvider(
diff --git
a/object-storage/src/main/java/org/apache/iotdb/os/io/test/TestObjectStorageConnector.java
b/object-storage/src/main/java/org/apache/iotdb/os/io/test/TestObjectStorageConnector.java
new file mode 100644
index 00000000000..70ee1a0d817
--- /dev/null
+++
b/object-storage/src/main/java/org/apache/iotdb/os/io/test/TestObjectStorageConnector.java
@@ -0,0 +1,80 @@
+/*
+ * 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.iotdb.os.io.test;
+
+import org.apache.iotdb.os.conf.ObjectStorageDescriptor;
+import org.apache.iotdb.os.conf.provider.TestConfig;
+import org.apache.iotdb.os.exception.ObjectStorageException;
+import org.apache.iotdb.os.fileSystem.OSURI;
+import org.apache.iotdb.os.io.IMetaData;
+import org.apache.iotdb.os.io.ObjectStorageConnector;
+
+import java.io.File;
+import java.io.InputStream;
+
+public class TestObjectStorageConnector implements ObjectStorageConnector {
+ private final TestConfig testConfig =
+ (TestConfig)
ObjectStorageDescriptor.getInstance().getConfig().getProviderConfig();
+
+ @Override
+ public boolean doesObjectExist(OSURI osUri) throws ObjectStorageException {
+ return false;
+ }
+
+ @Override
+ public IMetaData getMetaData(OSURI osUri) throws ObjectStorageException {
+ return null;
+ }
+
+ @Override
+ public boolean createNewEmptyObject(OSURI osUri) throws
ObjectStorageException {
+ return false;
+ }
+
+ @Override
+ public boolean delete(OSURI osUri) throws ObjectStorageException {
+ return false;
+ }
+
+ @Override
+ public boolean renameTo(OSURI fromOSUri, OSURI toOSUri) throws
ObjectStorageException {
+ return false;
+ }
+
+ @Override
+ public InputStream getInputStream(OSURI osUri) throws ObjectStorageException
{
+ return null;
+ }
+
+ @Override
+ public OSURI[] list(OSURI osUri) throws ObjectStorageException {
+ return new OSURI[0];
+ }
+
+ @Override
+ public void putLocalFile(OSURI osUri, File lcoalFile) throws
ObjectStorageException {}
+
+ @Override
+ public byte[] getRemoteFile(OSURI osUri, long position, int len) throws
ObjectStorageException {
+ return new byte[0];
+ }
+
+ @Override
+ public void copyRemoteFile(OSURI srcUri, OSURI destUri) throws
ObjectStorageException {}
+}
diff --git
a/object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
b/object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
index cb793bd366b..1548c2bab1d 100644
---
a/object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
+++
b/object-storage/src/main/java/org/apache/iotdb/os/utils/ObjectStorageType.java
@@ -21,6 +21,7 @@ package org.apache.iotdb.os.utils;
import org.apache.iotdb.os.conf.ObjectStorageDescriptor;
import org.apache.iotdb.os.io.ObjectStorageConnector;
import org.apache.iotdb.os.io.aws.S3ObjectStorageConnector;
+import org.apache.iotdb.os.io.test.TestObjectStorageConnector;
public enum ObjectStorageType {
TEST,
@@ -31,6 +32,7 @@ public enum ObjectStorageType {
case AWS_S3:
return new S3ObjectStorageConnector();
case TEST:
+ return new TestObjectStorageConnector();
default:
return null;
}
diff --git
a/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileCacheTest.java
b/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileCacheTest.java
index 0691687e3d7..2e76d3f84e1 100644
---
a/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileCacheTest.java
+++
b/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileCacheTest.java
@@ -26,7 +26,9 @@ import org.apache.iotdb.os.io.ObjectStorageConnector;
import org.apache.iotdb.os.utils.ObjectStorageType;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -56,9 +58,21 @@ public class OSFileCacheTest {
new OSFile(new OSURI("test_bucket", "test_key"), ObjectStorageType.TEST);
@Mock private ObjectStorageConnector connector;
+ private static ObjectStorageType prevObjectStorageType;
private int prevCachePageSize;
private String[] prevCacheDirs;
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ prevObjectStorageType = config.getOsType();
+ config.setOsType(ObjectStorageType.TEST);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ config.setOsType(prevObjectStorageType);
+ }
+
@Before
public void setUp() throws Exception {
prevCachePageSize = config.getCachePageSize();
diff --git
a/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileChannelTest.java
b/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileChannelTest.java
index 2eb3b5be4ec..eb6bcfa0f7d 100644
---
a/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileChannelTest.java
+++
b/object-storage/src/test/java/org/apache/iotdb/os/cache/OSFileChannelTest.java
@@ -28,7 +28,9 @@ import org.apache.iotdb.os.io.aws.S3MetaData;
import org.apache.iotdb.os.utils.ObjectStorageType;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -61,9 +63,21 @@ public class OSFileChannelTest {
new OSFile(new OSURI("test_bucket", "test_key"), ObjectStorageType.TEST);
@Mock private ObjectStorageConnector connector;
+ private static ObjectStorageType prevObjectStorageType;
private int prevCachePageSize;
private String[] prevCacheDirs;
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ prevObjectStorageType = config.getOsType();
+ config.setOsType(ObjectStorageType.TEST);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ config.setOsType(prevObjectStorageType);
+ }
+
@Before
public void setUp() throws Exception {
prevCachePageSize = config.getCachePageSize();
diff --git
a/object-storage/src/test/java/org/apache/iotdb/os/cache/OSInputStreamTest.java
b/object-storage/src/test/java/org/apache/iotdb/os/cache/OSInputStreamTest.java
index 50978182034..37574ec70df 100644
---
a/object-storage/src/test/java/org/apache/iotdb/os/cache/OSInputStreamTest.java
+++
b/object-storage/src/test/java/org/apache/iotdb/os/cache/OSInputStreamTest.java
@@ -28,7 +28,9 @@ import org.apache.iotdb.os.io.aws.S3MetaData;
import org.apache.iotdb.os.utils.ObjectStorageType;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
@@ -55,9 +57,21 @@ public class OSInputStreamTest {
new OSFile(new OSURI("test_bucket", "test_key"), ObjectStorageType.TEST);
@Mock private ObjectStorageConnector connector;
+ private static ObjectStorageType prevObjectStorageType;
private int prevCachePageSize;
private String[] prevCacheDirs;
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ prevObjectStorageType = config.getOsType();
+ config.setOsType(ObjectStorageType.TEST);
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ config.setOsType(prevObjectStorageType);
+ }
+
@Before
public void setUp() throws Exception {
prevCachePageSize = config.getCachePageSize();