Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoran10 committed Jun 7, 2021
1 parent 44012e0 commit 27c9fff
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- name: Spotbugs check
run: mvn spotbugs:check

- name: amqp-impl tests
run: mvn test -DfailIfNoTests=false -pl amqp-impl

- name: test after build
run: mvn test -DfailIfNoTests=false -pl tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.common.util.FutureUtil;
import org.apache.pulsar.metadata.api.MetadataCache;
import org.apache.pulsar.policies.data.loadbalancer.LocalBrokerData;
import org.apache.pulsar.policies.data.loadbalancer.ServiceLookupData;

/**
Expand All @@ -39,12 +40,12 @@ public class PulsarServiceLookupHandler implements LookupHandler {

private PulsarClientImpl pulsarClient;

private MetadataCache<ServiceLookupData> serviceLookupDataCache;
private MetadataCache<LocalBrokerData> serviceLookupDataCache;

public PulsarServiceLookupHandler(PulsarService pulsarService, PulsarClientImpl pulsarClient) {
this.pulsarService = pulsarService;
this.pulsarClient = pulsarClient;
this.serviceLookupDataCache = pulsarService.getLocalMetadataStore().getMetadataCache(ServiceLookupData.class);
this.serviceLookupDataCache = pulsarService.getLocalMetadataStore().getMetadataCache(LocalBrokerData.class);
}

@Override
Expand Down Expand Up @@ -73,7 +74,7 @@ public CompletableFuture<Pair<String, Integer>> findBroker(TopicName topicName,
}
}

List<CompletableFuture<Optional<ServiceLookupData>>> futureList = new ArrayList<>();
List<CompletableFuture<Optional<LocalBrokerData>>> futureList = new ArrayList<>();
for (String webService : matchWebUri) {
String path = LoadManager.LOADBALANCE_BROKERS_ROOT + "/" + webService;
futureList.add(serviceLookupDataCache.get(path));
Expand Down Expand Up @@ -109,8 +110,8 @@ public CompletableFuture<Pair<String, Integer>> findBroker(TopicName topicName,
return;
}
boolean match = false;
for (CompletableFuture<Optional<ServiceLookupData>> future : futureList) {
Optional<ServiceLookupData> optionalServiceLookupData = future.join();
for (CompletableFuture<Optional<LocalBrokerData>> future : futureList) {
Optional<LocalBrokerData> optionalServiceLookupData = future.join();
if (!optionalServiceLookupData.isPresent()) {
log.warn("Service lookup data is null.");
continue;
Expand Down
2 changes: 1 addition & 1 deletion amqp-impl/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</Console>
</Appenders>
<Loggers>
<Root level="warn">
<Root level="info">
<AppenderRef ref="Console" />
</Root>
<Logger name="org.eclipse.jetty" level="info"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Mockito.when(pulsarService.getConfiguration()).thenReturn(serviceConfiguration);
Mockito.when(pulsarService.getOrderedExecutor()).thenReturn(
OrderedExecutor.newBuilder().numThreads(8).name("pulsar-ordered").build());
Mockito.when(serviceConfiguration.getNumIOThreads()).thenReturn(2 * Runtime.getRuntime().availableProcessors());
}

private void mockBrokerService() {
Expand Down
6 changes: 6 additions & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<artifactId>qpid-test-utils</artifactId>
<version>${qpid-protocol-plugin.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.common.collect.Sets;
import com.google.common.util.concurrent.MoreExecutors;
import io.netty.channel.EventLoopGroup;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URI;
Expand All @@ -33,8 +34,6 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.function.Supplier;

import io.netty.channel.EventLoopGroup;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.bookkeeper.client.BookKeeper;
Expand Down Expand Up @@ -346,12 +345,17 @@ public CompletableFuture<ZooKeeper> create(String serverList, SessionType sessio
private BookKeeperClientFactory mockBookKeeperClientFactory = new BookKeeperClientFactory() {

@Override
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient, EventLoopGroup eventLoopGroup, Optional<Class<? extends EnsemblePlacementPolicy>> ensemblePlacementPolicyClass, Map<String, Object> ensemblePlacementPolicyProperties) throws IOException {
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient, EventLoopGroup eventLoopGroup,
Optional<Class<? extends EnsemblePlacementPolicy>> ensemblePlacementPolicyClass,
Map<String, Object> ensemblePlacementPolicyProperties) throws IOException {
return mockBookKeeper;
}

@Override
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient, EventLoopGroup eventLoopGroup, Optional<Class<? extends EnsemblePlacementPolicy>> ensemblePlacementPolicyClass, Map<String, Object> ensemblePlacementPolicyProperties, StatsLogger statsLogger) throws IOException {
public BookKeeper create(ServiceConfiguration conf, ZooKeeper zkClient, EventLoopGroup eventLoopGroup,
Optional<Class<? extends EnsemblePlacementPolicy>> ensemblePlacementPolicyClass,
Map<String, Object> ensemblePlacementPolicyProperties, StatsLogger statsLogger)
throws IOException {
return mockBookKeeper;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</Console>
</Appenders>
<Loggers>
<Root level="warn">
<Root level="info">
<AppenderRef ref="Console" />
</Root>
<Logger name="org.eclipse.jetty" level="info"/>
Expand Down

0 comments on commit 27c9fff

Please sign in to comment.