|
1 | 1 | /**
|
2 |
| - * Copyright 2009-2019 the original author or authors. |
| 2 | + * Copyright 2009-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
24 | 24 | import java.sql.SQLException;
|
25 | 25 | import java.util.Date;
|
26 | 26 | import java.util.List;
|
| 27 | +import java.util.concurrent.ExecutorService; |
| 28 | +import java.util.concurrent.Executors; |
| 29 | +import java.util.concurrent.Future; |
| 30 | +import java.util.stream.Collectors; |
| 31 | +import java.util.stream.IntStream; |
27 | 32 |
|
28 | 33 | import org.apache.ibatis.domain.misc.RichType;
|
29 | 34 | import org.junit.jupiter.api.BeforeEach;
|
@@ -215,4 +220,30 @@ class Address {
|
215 | 220 | typeHandlerRegistry.register(Address.class, StringTypeHandler.class);
|
216 | 221 | assertTrue(typeHandlerRegistry.hasTypeHandler(Address.class));
|
217 | 222 | }
|
| 223 | + |
| 224 | + enum TestEnum { |
| 225 | + ONE, |
| 226 | + TWO |
| 227 | + } |
| 228 | + |
| 229 | + @Test |
| 230 | + void shouldAutoRegisterEnutmTypeInMultiThreadEnvironment() throws Exception { |
| 231 | + // gh-1820 |
| 232 | + ExecutorService executorService = Executors.newCachedThreadPool(); |
| 233 | + try { |
| 234 | + for (int iteration = 0; iteration < 2000; iteration++) { |
| 235 | + TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry(); |
| 236 | + List<Future<Boolean>> taskResults = IntStream.range(0, 2) |
| 237 | + .mapToObj(taskIndex -> executorService.submit(() -> { |
| 238 | + return typeHandlerRegistry.hasTypeHandler(TestEnum.class, JdbcType.VARCHAR); |
| 239 | + })).collect(Collectors.toList()); |
| 240 | + for (int i = 0; i < taskResults.size(); i++) { |
| 241 | + Future<Boolean> future = taskResults.get(i); |
| 242 | + assertTrue(future.get(), "false is returned at round " + iteration); |
| 243 | + } |
| 244 | + } |
| 245 | + } finally { |
| 246 | + executorService.shutdownNow(); |
| 247 | + } |
| 248 | + } |
218 | 249 | }
|
0 commit comments