|
24 | 24 | import software.amazon.awssdk.services.s3.auth.scheme.S3AuthSchemeProvider; |
25 | 25 | import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; |
26 | 26 | import software.amazon.awssdk.regions.Region; |
| 27 | +import java.util.concurrent.CountDownLatch; |
| 28 | +import java.util.concurrent.ExecutorService; |
| 29 | +import java.util.concurrent.Executors; |
| 30 | +import java.util.concurrent.TimeUnit; |
| 31 | +import java.util.concurrent.atomic.AtomicInteger; |
27 | 32 |
|
28 | 33 | public class S3AccessGrantsPluginTests { |
29 | 34 |
|
@@ -156,4 +161,38 @@ public void create_access_grants_plugin_without_userAgent_specified() { |
156 | 161 | public void create_access_grants_plugin_with_not_permitted_userAgent_name() { |
157 | 162 | Assertions.assertThatThrownBy(() -> S3AccessGrantsPlugin.builder().userAgent("testUserAgent/").build()).isInstanceOf(IllegalArgumentException.class); |
158 | 163 | } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void configureClient_concurrent_access_should_not_throw_null_pointer_exception() throws InterruptedException { |
| 167 | + S3AccessGrantsPlugin accessGrantsPlugin = S3AccessGrantsPlugin.builder().build(); |
| 168 | + int threadCount = 10; |
| 169 | + ExecutorService executor = Executors.newFixedThreadPool(threadCount); |
| 170 | + CountDownLatch latch = new CountDownLatch(threadCount); |
| 171 | + AtomicInteger successCount = new AtomicInteger(0); |
| 172 | + AtomicInteger exceptionCount = new AtomicInteger(0); |
| 173 | + |
| 174 | + for (int i = 0; i < threadCount; i++) { |
| 175 | + executor.submit(() -> { |
| 176 | + try { |
| 177 | + SdkServiceClientConfiguration.Builder config = S3ServiceClientConfiguration.builder() |
| 178 | + .authSchemeProvider(S3AuthSchemeProvider.defaultProvider()) |
| 179 | + .credentialsProvider(DefaultCredentialsProvider.create()) |
| 180 | + .region(Region.US_EAST_2); |
| 181 | + |
| 182 | + accessGrantsPlugin.configureClient(config); |
| 183 | + successCount.incrementAndGet(); |
| 184 | + } catch (Exception e) { |
| 185 | + exceptionCount.incrementAndGet(); |
| 186 | + } finally { |
| 187 | + latch.countDown(); |
| 188 | + } |
| 189 | + }); |
| 190 | + } |
| 191 | + |
| 192 | + latch.await(10, TimeUnit.SECONDS); |
| 193 | + executor.shutdown(); |
| 194 | + |
| 195 | + Assertions.assertThat(successCount.get()).isEqualTo(threadCount); |
| 196 | + Assertions.assertThat(exceptionCount.get()).isEqualTo(0); |
| 197 | + } |
159 | 198 | } |
0 commit comments