io.scalecube.services.benchmarks.gateway.AbstractBenchmarkState Maven / Gradle / Ivy
package io.scalecube.services.benchmarks.gateway;
import io.scalecube.benchmarks.BenchmarkSettings;
import io.scalecube.benchmarks.BenchmarkState;
import io.scalecube.net.Address;
import io.scalecube.services.Microservices;
import io.scalecube.services.api.ServiceMessage;
import io.scalecube.services.gateway.ReferenceCountUtil;
import io.scalecube.services.gateway.transport.GatewayClient;
import java.util.Optional;
import java.util.function.Function;
import java.util.logging.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
import reactor.core.publisher.SignalType;
public abstract class AbstractBenchmarkState>
extends BenchmarkState {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractBenchmarkState.class);
public static final ServiceMessage FIRST_REQUEST =
ServiceMessage.builder().qualifier("/benchmarks/one").build();
protected Function clientBuilder;
public AbstractBenchmarkState(
BenchmarkSettings settings, Function clientBuilder) {
super(settings);
this.clientBuilder = clientBuilder;
}
@Override
protected void beforeAll() throws Exception {
super.beforeAll();
int workerCount = Runtime.getRuntime().availableProcessors();
}
public abstract Mono createClient();
protected final Mono createClient(
Microservices gateway, String gatewayName, Function clientBuilder) {
return Mono.defer(() -> createClient(gateway.gateway(gatewayName).address(), clientBuilder));
}
protected final Mono createClient(
Address gatewayAddress, Function clientBuilder) {
return Mono.defer(
() -> {
GatewayClient client = clientBuilder.apply(gatewayAddress);
return client
.requestResponse(FIRST_REQUEST)
.log("benchmark-client-first-request", Level.INFO, false, SignalType.ON_NEXT)
.doOnNext(
response ->
Optional.ofNullable(response.data())
.ifPresent(ReferenceCountUtil::safestRelease))
.then(Mono.just(client))
.doOnNext(c -> LOGGER.info("benchmark-client: {}", c));
});
}
}