Skip to content

Commit 82e4679

Browse files
committed
Increase some tests performance
https://build.spring.io/browse/INT-MASTER-999/ Since `BeanFactoryTypeConverterTests` and `CallerBlocksPolicyTests` uses too long `Thread.sleep()` there is no guarantee that they are going to be performed after expected 10 seconds * Decrease `Thread.sleep()` in those tests
1 parent 6216075 commit 82e4679

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -77,7 +77,7 @@ public class BeanFactoryTypeConverterTests {
7777
@Test
7878
public void testEmptyCollectionConversion() {
7979
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
80-
List<String> sourceObject = new ArrayList<String>();
80+
List<String> sourceObject = new ArrayList<>();
8181
ArrayList<BeanFactoryTypeConverterTests> convertedCollection =
8282
(ArrayList<BeanFactoryTypeConverterTests>) typeConverter.convertValue(sourceObject,
8383
TypeDescriptor.forObject(sourceObject),
@@ -101,15 +101,15 @@ public void testToNonStringConversionNotSupportedByGenericConversionService() {
101101
@SuppressWarnings("unchecked")
102102
Collection<Integer> converted = (Collection<Integer>) typeConverter.convertValue(1234,
103103
TypeDescriptor.valueOf(Integer.class),
104-
TypeDescriptor.forObject(new ArrayList<Integer>(Arrays.asList(1))));
104+
TypeDescriptor.forObject(new ArrayList<>(Arrays.asList(1))));
105105
assertEquals(Arrays.asList(1234), converted);
106106
}
107107

108108
@Test
109109
public void testMessageHeadersNotConverted() {
110110
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
111111
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
112-
MessageHeaders headers = new GenericMessage<String>("foo").getHeaders();
112+
MessageHeaders headers = new GenericMessage<>("foo").getHeaders();
113113
assertSame(headers, typeConverter.convertValue(headers, TypeDescriptor.valueOf(MessageHeaders.class),
114114
TypeDescriptor.valueOf(MessageHeaders.class)));
115115
}
@@ -118,7 +118,7 @@ public void testMessageHeadersNotConverted() {
118118
public void testMessageHistoryNotConverted() {
119119
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
120120
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
121-
Message<String> message = new GenericMessage<String>("foo");
121+
Message<String> message = new GenericMessage<>("foo");
122122
message = MessageHistory.write(message, new NamedComponent() {
123123
@Override
124124
public String getComponentName() {
@@ -172,7 +172,7 @@ public void testObjectToStringIsConverted() {
172172
public void testMapOfMapOfCollectionIsConverted() {
173173
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
174174
DefaultConversionService conversionService = new DefaultConversionService();
175-
conversionService.addConverter(new Converter<Foo, Bar>() {
175+
conversionService.addConverter(new Converter<Foo, Bar>() { // Must be explicit type with generics
176176
@Override
177177
public Bar convert(Foo source) {
178178
return new Bar();
@@ -189,11 +189,11 @@ public Bar convert(Foo source) {
189189
TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class),
190190
TypeDescriptor.collection(Set.class, TypeDescriptor.valueOf(Bar.class))));
191191

192-
Set<Foo> fooSet = new HashSet<Foo>();
192+
Set<Foo> fooSet = new HashSet<>();
193193
fooSet.add(new Foo());
194194
Map<String, Set<Foo>> fooMap = new HashMap<String, Set<Foo>>();
195195
fooMap.put("foo", fooSet);
196-
foos = new HashMap<String, Map<String, Set<Foo>>>();
196+
foos = new HashMap<>();
197197
foos.put("foo", fooMap);
198198

199199
bars = (Map<String, Map<String, Set<Bar>>>) typeConverter.convertValue(foos, sourceType, targetType);
@@ -206,7 +206,7 @@ public Bar convert(Foo source) {
206206
ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
207207
QueueChannel replyChannel = new QueueChannel();
208208
handler.setOutputChannel(replyChannel);
209-
handler.handleMessage(new GenericMessage<Map<String, Map<String, Set<Foo>>>>(foos));
209+
handler.handleMessage(new GenericMessage<>(foos));
210210
Message<?> message = replyChannel.receive(0);
211211
assertNotNull(message);
212212
assertEquals("bar", message.getPayload());
@@ -216,7 +216,7 @@ public Bar convert(Foo source) {
216216
public void testCollectionIsConverted() {
217217
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
218218
DefaultConversionService conversionService = new DefaultConversionService();
219-
conversionService.addConverter(new Converter<Foo, Bar>() {
219+
conversionService.addConverter(new Converter<Foo, Bar>() { // Must be explicit type with generics
220220
@Override
221221
public Bar convert(Foo source) {
222222
return new Bar();
@@ -271,7 +271,7 @@ public void testEditorWithTargetString() {
271271
public void testEditorWithTargetFoo() {
272272
DefaultConversionService conversionService = new DefaultConversionService();
273273
final Foo foo = new Foo();
274-
conversionService.addConverter(new Converter<String, Foo>() {
274+
conversionService.addConverter(new Converter<String, Foo>() { // Must be explicit type with generics
275275
@Override
276276
public Foo convert(String source) {
277277
return foo;
@@ -306,9 +306,9 @@ public void initialConcurrency() throws Exception {
306306
final AtomicInteger count = new AtomicInteger();
307307
doAnswer(invocation -> {
308308
count.incrementAndGet();
309-
Thread.sleep(500);
309+
Thread.sleep(100);
310310
concurrentlyInGetDefaultEditor.set(inGetDefaultEditor.getAndSet(true));
311-
Thread.sleep(500);
311+
Thread.sleep(100);
312312
inGetDefaultEditor.set(false);
313313
return invocation.callRealMethod();
314314
}).when(typeConverter).getDefaultEditor(UUID.class);

spring-integration-core/src/test/java/org/springframework/integration/util/CallerBlocksPolicyTests.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2017 the original author or authors.
2+
* Copyright 2014-2018 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.
@@ -35,6 +35,7 @@
3535
/**
3636
* @author Gary Russell
3737
* @author Artem Bilan
38+
*
3839
* @since 3.0.3
3940
*
4041
*/
@@ -46,9 +47,9 @@ public void test0() throws Exception {
4647
te.setCorePoolSize(1);
4748
te.setMaxPoolSize(1);
4849
te.setQueueCapacity(0);
49-
te.setRejectedExecutionHandler(new CallerBlocksPolicy(1000));
50+
te.setRejectedExecutionHandler(new CallerBlocksPolicy(10));
5051
te.initialize();
51-
final AtomicReference<Throwable> e = new AtomicReference<Throwable>();
52+
final AtomicReference<Throwable> e = new AtomicReference<>();
5253
final CountDownLatch latch = new CountDownLatch(1);
5354
Runnable task = new Runnable() {
5455

@@ -82,19 +83,15 @@ public void test1() throws Exception {
8283
final CountDownLatch latch = new CountDownLatch(3);
8384
te.execute(() -> {
8485
try {
85-
Runnable foo = new Runnable() {
86-
87-
@Override
88-
public void run() {
89-
try {
90-
Thread.sleep(1000);
91-
}
92-
catch (InterruptedException e) {
93-
Thread.currentThread().interrupt();
94-
throw new RuntimeException();
95-
}
96-
latch.countDown();
86+
Runnable foo = () -> {
87+
try {
88+
Thread.sleep(10);
89+
}
90+
catch (InterruptedException e1) {
91+
Thread.currentThread().interrupt();
92+
throw new RuntimeException();
9793
}
94+
latch.countDown();
9895
};
9996
te.execute(foo);
10097
te.execute(foo); // this one will be queued

0 commit comments

Comments
 (0)