Skip to content

Commit 48617c8

Browse files
committed
Simplify failing test
1 parent c568ff2 commit 48617c8

File tree

1 file changed

+12
-47
lines changed

1 file changed

+12
-47
lines changed

src/test/java/com/fasterxml/jackson/failing/RaceCondition738Test.java

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@
88
import com.fasterxml.jackson.databind.BaseMapTest;
99
import com.fasterxml.jackson.databind.JsonNode;
1010
import com.fasterxml.jackson.databind.ObjectMapper;
11-
import com.fasterxml.jackson.databind.module.SimpleModule;
1211

1312
public class RaceCondition738Test extends BaseMapTest
1413
{
15-
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
16-
@JsonSubTypes({
17-
@JsonSubTypes.Type(value = TypeOne.class, name = "one"),
18-
@JsonSubTypes.Type(value = TypeTwo.class, name = "two"),
19-
@JsonSubTypes.Type(value = TypeThree.class, name = "three")
20-
})
2114
static abstract class AbstractHasSubTypes implements HasSubTypes { }
2215

2316
static class TypeOne extends AbstractHasSubTypes {
@@ -35,36 +28,10 @@ public String getType() {
3528
}
3629
}
3730

38-
static class TypeTwo extends AbstractHasSubTypes {
39-
private final String id;
40-
public TypeTwo(String id) {
41-
this.id = id;
42-
}
43-
@JsonProperty
44-
public String getId() {
45-
return id;
46-
}
47-
@Override
48-
public String getType() {
49-
return TypeTwo.class.getSimpleName();
50-
}
51-
}
52-
53-
static class TypeThree extends AbstractHasSubTypes {
54-
private final String id;
55-
public TypeThree(String id) {
56-
this.id = id;
57-
}
58-
@JsonProperty
59-
public String getId() {
60-
return id;
61-
}
62-
@Override
63-
public String getType() {
64-
return TypeThree.class.getSimpleName();
65-
}
66-
}
67-
31+
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
32+
@JsonSubTypes({
33+
@JsonSubTypes.Type(value = TypeOne.class, name = "one")
34+
})
6835
public interface HasSubTypes {
6936
String getType();
7037
}
@@ -89,12 +56,13 @@ public HasSubTypes getHasSubTypes() {
8956
*/
9057

9158
public void testRepeatedly() throws Exception {
92-
for (int i = 0; i < 1000; i++) {
93-
runOnce();
59+
final int COUNT = 50;
60+
for (int i = 0; i < COUNT; i++) {
61+
runOnce(i, COUNT);
9462
}
9563
}
9664

97-
void runOnce() throws Exception {
65+
void runOnce(int round, int max) throws Exception {
9866
final ObjectMapper mapper = getObjectMapper();
9967
Callable<String> writeJson = new Callable<String>() {
10068
@Override
@@ -120,17 +88,14 @@ public String call() throws Exception {
12088
JsonNode wrapped = tree.get("hasSubTypes");
12189

12290
if (!wrapped.has("one")) {
123-
throw new IllegalStateException("Missing 'one', source: "+json);
91+
System.out.println("JSON wrong: "+json);
92+
throw new IllegalStateException("Round #"+round+"/"+max+" ; missing property 'one', source: "+json);
12493
}
94+
System.out.println("JSON fine: "+json);
12595
}
12696
}
12797

12898
private static ObjectMapper getObjectMapper() {
129-
SimpleModule module = new SimpleModule("subTypeRace");
130-
module.setMixInAnnotation(HasSubTypes.class, AbstractHasSubTypes.class);
131-
132-
ObjectMapper mapper = new ObjectMapper();
133-
mapper.registerModule(module);
134-
return mapper;
99+
return new ObjectMapper();
135100
}
136101
}

0 commit comments

Comments
 (0)