Skip to content

Commit

Permalink
Increase some tests performance
Browse files Browse the repository at this point in the history
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
  • Loading branch information
artembilan committed Apr 11, 2018
1 parent 6216075 commit 82e4679
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -77,7 +77,7 @@ public class BeanFactoryTypeConverterTests {
@Test
public void testEmptyCollectionConversion() {
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
List<String> sourceObject = new ArrayList<String>();
List<String> sourceObject = new ArrayList<>();
ArrayList<BeanFactoryTypeConverterTests> convertedCollection =
(ArrayList<BeanFactoryTypeConverterTests>) typeConverter.convertValue(sourceObject,
TypeDescriptor.forObject(sourceObject),
Expand All @@ -101,15 +101,15 @@ public void testToNonStringConversionNotSupportedByGenericConversionService() {
@SuppressWarnings("unchecked")
Collection<Integer> converted = (Collection<Integer>) typeConverter.convertValue(1234,
TypeDescriptor.valueOf(Integer.class),
TypeDescriptor.forObject(new ArrayList<Integer>(Arrays.asList(1))));
TypeDescriptor.forObject(new ArrayList<>(Arrays.asList(1))));
assertEquals(Arrays.asList(1234), converted);
}

@Test
public void testMessageHeadersNotConverted() {
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
MessageHeaders headers = new GenericMessage<String>("foo").getHeaders();
MessageHeaders headers = new GenericMessage<>("foo").getHeaders();
assertSame(headers, typeConverter.convertValue(headers, TypeDescriptor.valueOf(MessageHeaders.class),
TypeDescriptor.valueOf(MessageHeaders.class)));
}
Expand All @@ -118,7 +118,7 @@ public void testMessageHeadersNotConverted() {
public void testMessageHistoryNotConverted() {
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
Message<String> message = new GenericMessage<String>("foo");
Message<String> message = new GenericMessage<>("foo");
message = MessageHistory.write(message, new NamedComponent() {
@Override
public String getComponentName() {
Expand Down Expand Up @@ -172,7 +172,7 @@ public void testObjectToStringIsConverted() {
public void testMapOfMapOfCollectionIsConverted() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<Foo, Bar>() {
conversionService.addConverter(new Converter<Foo, Bar>() { // Must be explicit type with generics
@Override
public Bar convert(Foo source) {
return new Bar();
Expand All @@ -189,11 +189,11 @@ public Bar convert(Foo source) {
TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class),
TypeDescriptor.collection(Set.class, TypeDescriptor.valueOf(Bar.class))));

Set<Foo> fooSet = new HashSet<Foo>();
Set<Foo> fooSet = new HashSet<>();
fooSet.add(new Foo());
Map<String, Set<Foo>> fooMap = new HashMap<String, Set<Foo>>();
fooMap.put("foo", fooSet);
foos = new HashMap<String, Map<String, Set<Foo>>>();
foos = new HashMap<>();
foos.put("foo", fooMap);

bars = (Map<String, Map<String, Set<Bar>>>) typeConverter.convertValue(foos, sourceType, targetType);
Expand All @@ -206,7 +206,7 @@ public Bar convert(Foo source) {
ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
QueueChannel replyChannel = new QueueChannel();
handler.setOutputChannel(replyChannel);
handler.handleMessage(new GenericMessage<Map<String, Map<String, Set<Foo>>>>(foos));
handler.handleMessage(new GenericMessage<>(foos));
Message<?> message = replyChannel.receive(0);
assertNotNull(message);
assertEquals("bar", message.getPayload());
Expand All @@ -216,7 +216,7 @@ public Bar convert(Foo source) {
public void testCollectionIsConverted() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
DefaultConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<Foo, Bar>() {
conversionService.addConverter(new Converter<Foo, Bar>() { // Must be explicit type with generics
@Override
public Bar convert(Foo source) {
return new Bar();
Expand Down Expand Up @@ -271,7 +271,7 @@ public void testEditorWithTargetString() {
public void testEditorWithTargetFoo() {
DefaultConversionService conversionService = new DefaultConversionService();
final Foo foo = new Foo();
conversionService.addConverter(new Converter<String, Foo>() {
conversionService.addConverter(new Converter<String, Foo>() { // Must be explicit type with generics
@Override
public Foo convert(String source) {
return foo;
Expand Down Expand Up @@ -306,9 +306,9 @@ public void initialConcurrency() throws Exception {
final AtomicInteger count = new AtomicInteger();
doAnswer(invocation -> {
count.incrementAndGet();
Thread.sleep(500);
Thread.sleep(100);
concurrentlyInGetDefaultEditor.set(inGetDefaultEditor.getAndSet(true));
Thread.sleep(500);
Thread.sleep(100);
inGetDefaultEditor.set(false);
return invocation.callRealMethod();
}).when(typeConverter).getDefaultEditor(UUID.class);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,7 @@
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 3.0.3
*
*/
Expand All @@ -46,9 +47,9 @@ public void test0() throws Exception {
te.setCorePoolSize(1);
te.setMaxPoolSize(1);
te.setQueueCapacity(0);
te.setRejectedExecutionHandler(new CallerBlocksPolicy(1000));
te.setRejectedExecutionHandler(new CallerBlocksPolicy(10));
te.initialize();
final AtomicReference<Throwable> e = new AtomicReference<Throwable>();
final AtomicReference<Throwable> e = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
Runnable task = new Runnable() {

Expand Down Expand Up @@ -82,19 +83,15 @@ public void test1() throws Exception {
final CountDownLatch latch = new CountDownLatch(3);
te.execute(() -> {
try {
Runnable foo = new Runnable() {

@Override
public void run() {
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException();
}
latch.countDown();
Runnable foo = () -> {
try {
Thread.sleep(10);
}
catch (InterruptedException e1) {
Thread.currentThread().interrupt();
throw new RuntimeException();
}
latch.countDown();
};
te.execute(foo);
te.execute(foo); // this one will be queued
Expand Down

0 comments on commit 82e4679

Please sign in to comment.