Skip to content

Commit beeb15f

Browse files
committed
Polishing
- Moved the test case and simplified it a little bit. - Updated license years.
1 parent 1f4528e commit beeb15f

File tree

4 files changed

+33
-78
lines changed

4 files changed

+33
-78
lines changed

src/main/java/org/apache/ibatis/type/TypeHandlerRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/test/java/org/apache/ibatis/submitted/typehandlerregistry_race_condition/TestEnum.java

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/test/java/org/apache/ibatis/submitted/typehandlerregistry_race_condition/TypeHandlerRegistryHasHandlerRaceConditionTest.java

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/test/java/org/apache/ibatis/type/TypeHandlerRegistryTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2019 the original author or authors.
2+
* Copyright 2009-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,11 @@
2424
import java.sql.SQLException;
2525
import java.util.Date;
2626
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;
2732

2833
import org.apache.ibatis.domain.misc.RichType;
2934
import org.junit.jupiter.api.BeforeEach;
@@ -215,4 +220,30 @@ class Address {
215220
typeHandlerRegistry.register(Address.class, StringTypeHandler.class);
216221
assertTrue(typeHandlerRegistry.hasTypeHandler(Address.class));
217222
}
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+
}
218249
}

0 commit comments

Comments
 (0)