Reduce dependency on Guava 2 (#1590)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -10,9 +10,11 @@
|
||||
package org.eclipse.hawkbit.repository.test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.eclipse.hawkbit.ContextAware;
|
||||
import org.eclipse.hawkbit.ControllerPollProperties;
|
||||
@@ -69,7 +71,7 @@ import org.springframework.security.concurrent.DelegatingSecurityContextExecutor
|
||||
import org.springframework.security.concurrent.DelegatingSecurityContextScheduledExecutorService;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Spring context configuration required for Dev.Environment.
|
||||
@@ -209,8 +211,15 @@ public class TestConfiguration implements AsyncConfigurer {
|
||||
|
||||
@Bean
|
||||
public ScheduledExecutorService scheduledExecutorService() {
|
||||
return new DelegatingSecurityContextScheduledExecutorService(Executors.newScheduledThreadPool(1,
|
||||
new ThreadFactoryBuilder().setNameFormat("central-scheduled-executor-pool-%d").build()));
|
||||
final AtomicLong count = new AtomicLong(0);
|
||||
return new DelegatingSecurityContextScheduledExecutorService(
|
||||
Executors.newScheduledThreadPool(1, (runnable) -> {
|
||||
final Thread thread = Executors.defaultThreadFactory().newThread(runnable);
|
||||
thread.setName(
|
||||
String.format(
|
||||
Locale.ROOT, "central-scheduled-executor-pool-%d", count.getAndIncrement()));
|
||||
return thread;
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,16 +15,15 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.common.collect.ConcurrentHashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.awaitility.core.ConditionTimeoutException;
|
||||
import org.eclipse.hawkbit.repository.event.remote.RemoteIdEvent;
|
||||
@@ -137,7 +136,7 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
|
||||
private static class EventCaptor implements ApplicationListener<RemoteApplicationEvent> {
|
||||
|
||||
private final Multiset<Class<?>> capturedEvents = ConcurrentHashMultiset.create();
|
||||
private final ConcurrentHashMap<Class<?>, Integer> capturedEvents = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(final RemoteApplicationEvent event) {
|
||||
@@ -162,18 +161,18 @@ public class EventVerifier extends AbstractTestExecutionListener {
|
||||
assertThat(((TargetAssignDistributionSetEvent) event).getDistributionSetId()).isNotNull();
|
||||
}
|
||||
|
||||
capturedEvents.add(event.getClass());
|
||||
capturedEvents.compute(event.getClass(), (k, v) -> v == null ? 1 : v + 1);
|
||||
}
|
||||
|
||||
public int getCountFor(final Class<?> expectedEvent) {
|
||||
return capturedEvents.count(expectedEvent);
|
||||
return Optional.ofNullable(capturedEvents.get(expectedEvent)).orElse(0);
|
||||
}
|
||||
|
||||
public Set<Class<?>> diff(final Expect[] allEvents) {
|
||||
return Sets.difference(capturedEvents.elementSet(),
|
||||
Stream.of(allEvents).map(Expect::type).collect(Collectors.toSet()));
|
||||
final Set<Class<?>> keys = new HashSet<>(capturedEvents.keySet());
|
||||
keys.removeAll(Stream.of(allEvents).map(Expect::type).collect(Collectors.toSet()));
|
||||
return keys;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class ResetCounterMarkerEvent extends RemoteApplicationEvent {
|
||||
|
||||
Reference in New Issue
Block a user