|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.hugegraph.store.cloud; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertFalse; |
| 22 | +import static org.junit.Assert.assertNotNull; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | + |
| 25 | +import java.util.HashMap; |
| 26 | +import java.util.Map; |
| 27 | + |
| 28 | +import org.junit.Before; |
| 29 | +import org.junit.Test; |
| 30 | + |
| 31 | +public class CloudStorageConfigTest { |
| 32 | + |
| 33 | + private CloudStorageConfig config; |
| 34 | + |
| 35 | + @Before |
| 36 | + public void setUp() { |
| 37 | + config = new CloudStorageConfig(); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Test CloudStorageConfig defaults |
| 42 | + */ |
| 43 | + @Test |
| 44 | + public void testDefaults() { |
| 45 | + assertFalse(config.isEnabled()); |
| 46 | + assertEquals("s3", config.getProvider()); |
| 47 | + assertEquals("hugegraph", config.getPathPrefix()); |
| 48 | + assertTrue(config.isStartupHydrationEnabled()); |
| 49 | + assertEquals(3000L, config.getReadMissGuardWindowMs()); |
| 50 | + assertNotNull(config.getExtraProperties()); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Test enabled flag setter and getter |
| 55 | + */ |
| 56 | + @Test |
| 57 | + public void testEnabledFlag() { |
| 58 | + assertFalse(config.isEnabled()); |
| 59 | + |
| 60 | + config.setEnabled(true); |
| 61 | + assertTrue(config.isEnabled()); |
| 62 | + |
| 63 | + config.setEnabled(false); |
| 64 | + assertFalse(config.isEnabled()); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Test provider setter and getter |
| 69 | + */ |
| 70 | + @Test |
| 71 | + public void testProvider() { |
| 72 | + assertEquals("s3", config.getProvider()); |
| 73 | + |
| 74 | + config.setProvider("gcs"); |
| 75 | + assertEquals("gcs", config.getProvider()); |
| 76 | + |
| 77 | + config.setProvider("azure"); |
| 78 | + assertEquals("azure", config.getProvider()); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Test bucket setter and getter |
| 83 | + */ |
| 84 | + @Test |
| 85 | + public void testBucket() { |
| 86 | + config.setBucket("my-bucket"); |
| 87 | + assertEquals("my-bucket", config.getBucket()); |
| 88 | + |
| 89 | + config.setBucket("another-bucket-123"); |
| 90 | + assertEquals("another-bucket-123", config.getBucket()); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Test region setter and getter |
| 95 | + */ |
| 96 | + @Test |
| 97 | + public void testRegion() { |
| 98 | + config.setRegion("us-east-1"); |
| 99 | + assertEquals("us-east-1", config.getRegion()); |
| 100 | + |
| 101 | + config.setRegion("eu-west-1"); |
| 102 | + assertEquals("eu-west-1", config.getRegion()); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Test endpoint setter and getter |
| 107 | + */ |
| 108 | + @Test |
| 109 | + public void testEndpoint() { |
| 110 | + config.setEndpoint("https://s3.amazonaws.com"); |
| 111 | + assertEquals("https://s3.amazonaws.com", config.getEndpoint()); |
| 112 | + |
| 113 | + config.setEndpoint("https://minio.example.com"); |
| 114 | + assertEquals("https://minio.example.com", config.getEndpoint()); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Test accessKey setter and getter |
| 119 | + */ |
| 120 | + @Test |
| 121 | + public void testAccessKey() { |
| 122 | + config.setAccessKey("AKIAIOSFODNN7EXAMPLE"); |
| 123 | + assertEquals("AKIAIOSFODNN7EXAMPLE", config.getAccessKey()); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Test secretKey setter and getter |
| 128 | + */ |
| 129 | + @Test |
| 130 | + public void testSecretKey() { |
| 131 | + config.setSecretKey("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"); |
| 132 | + assertEquals("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", config.getSecretKey()); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Test pathPrefix setter and getter |
| 137 | + */ |
| 138 | + @Test |
| 139 | + public void testPathPrefix() { |
| 140 | + assertEquals("hugegraph", config.getPathPrefix()); |
| 141 | + |
| 142 | + config.setPathPrefix("myapp/data"); |
| 143 | + assertEquals("myapp/data", config.getPathPrefix()); |
| 144 | + } |
| 145 | + |
| 146 | + /** |
| 147 | + * Test startupHydrationEnabled setter and getter |
| 148 | + */ |
| 149 | + @Test |
| 150 | + public void testStartupHydrationEnabled() { |
| 151 | + assertTrue(config.isStartupHydrationEnabled()); |
| 152 | + |
| 153 | + config.setStartupHydrationEnabled(false); |
| 154 | + assertFalse(config.isStartupHydrationEnabled()); |
| 155 | + |
| 156 | + config.setStartupHydrationEnabled(true); |
| 157 | + assertTrue(config.isStartupHydrationEnabled()); |
| 158 | + } |
| 159 | + |
| 160 | + /** |
| 161 | + * Test readMissGuardWindowMs setter and getter |
| 162 | + */ |
| 163 | + @Test |
| 164 | + public void testReadMissGuardWindowMs() { |
| 165 | + assertEquals(3000L, config.getReadMissGuardWindowMs()); |
| 166 | + |
| 167 | + config.setReadMissGuardWindowMs(5000L); |
| 168 | + assertEquals(5000L, config.getReadMissGuardWindowMs()); |
| 169 | + |
| 170 | + config.setReadMissGuardWindowMs(0L); |
| 171 | + assertEquals(0L, config.getReadMissGuardWindowMs()); |
| 172 | + |
| 173 | + config.setReadMissGuardWindowMs(-1L); |
| 174 | + assertEquals(-1L, config.getReadMissGuardWindowMs()); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Test extraProperties setter and getter |
| 179 | + */ |
| 180 | + @Test |
| 181 | + public void testExtraProperties() { |
| 182 | + Map<String, String> props = new HashMap<>(); |
| 183 | + props.put("key1", "value1"); |
| 184 | + props.put("key2", "value2"); |
| 185 | + |
| 186 | + config.setExtraProperties(props); |
| 187 | + |
| 188 | + assertNotNull(config.getExtraProperties()); |
| 189 | + assertEquals(2, config.getExtraProperties().size()); |
| 190 | + assertEquals("value1", config.getExtraProperties().get("key1")); |
| 191 | + assertEquals("value2", config.getExtraProperties().get("key2")); |
| 192 | + } |
| 193 | + |
| 194 | + /** |
| 195 | + * Test complete configuration |
| 196 | + */ |
| 197 | + @Test |
| 198 | + public void testCompleteConfiguration() { |
| 199 | + config.setEnabled(true); |
| 200 | + config.setProvider("s3"); |
| 201 | + config.setBucket("hugegraph-backup"); |
| 202 | + config.setRegion("us-west-2"); |
| 203 | + config.setEndpoint("https://s3-us-west-2.amazonaws.com"); |
| 204 | + config.setAccessKey("test-access-key"); |
| 205 | + config.setSecretKey("test-secret-key"); |
| 206 | + config.setPathPrefix("production/data"); |
| 207 | + config.setStartupHydrationEnabled(true); |
| 208 | + config.setReadMissGuardWindowMs(5000L); |
| 209 | + |
| 210 | + Map<String, String> extra = new HashMap<>(); |
| 211 | + extra.put("enable-versioning", "true"); |
| 212 | + extra.put("enable-encryption", "true"); |
| 213 | + config.setExtraProperties(extra); |
| 214 | + |
| 215 | + // Verify all settings |
| 216 | + assertTrue(config.isEnabled()); |
| 217 | + assertEquals("s3", config.getProvider()); |
| 218 | + assertEquals("hugegraph-backup", config.getBucket()); |
| 219 | + assertEquals("us-west-2", config.getRegion()); |
| 220 | + assertEquals("https://s3-us-west-2.amazonaws.com", config.getEndpoint()); |
| 221 | + assertEquals("test-access-key", config.getAccessKey()); |
| 222 | + assertEquals("test-secret-key", config.getSecretKey()); |
| 223 | + assertEquals("production/data", config.getPathPrefix()); |
| 224 | + assertTrue(config.isStartupHydrationEnabled()); |
| 225 | + assertEquals(5000L, config.getReadMissGuardWindowMs()); |
| 226 | + assertEquals(2, config.getExtraProperties().size()); |
| 227 | + } |
| 228 | +} |
| 229 | + |
0 commit comments