Skip to content

Commit

Permalink
reformat, optimize imports
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Malafeev <sergeymalafeev@gmail.com>
  • Loading branch information
malafeev committed Oct 3, 2018
1 parent 9c54e18 commit b6e9df4
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 69 deletions.
4 changes: 3 additions & 1 deletion opentracing-redis-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>opentracing-redis-parent</artifactId>
<groupId>io.opentracing.contrib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

public class RedisSpanNameProvider {

public static Function<String, String> OPERATION_NAME = (operationName) -> ((operationName == null) ? "unknown" : operationName);
public static Function<String, String> OPERATION_NAME = (operationName) ->
((operationName == null) ? "unknown" : operationName);


public static Function<String, String> PREFIX_OPERATION_NAME(final String prefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public TracingHelper(Tracer tracer, boolean traceWithActiveSpanOnly) {
this.spanNameProvider = RedisSpanNameProvider.OPERATION_NAME;
}

public TracingHelper(Tracer tracer, boolean traceWithActiveSpanOnly, Function<String, String> spanNameProvider) {
public TracingHelper(Tracer tracer, boolean traceWithActiveSpanOnly,
Function<String, String> spanNameProvider) {
this.tracer = tracer;
this.traceWithActiveSpanOnly = traceWithActiveSpanOnly;
this.spanNameProvider = spanNameProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@

package io.opentracing.contrib.redis.common;

import java.util.function.Function;
import static org.junit.Assert.assertEquals;

import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;


public class RedisSpanNameProviderTest {

private String prefix = "redis.";
String actual = "";
Function<String, String> prefixSpanName;
private String actual = "";
private Function<String, String> prefixSpanName;

@Before
public void setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@

package io.opentracing.contrib.redis.common;

import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

import io.opentracing.Tracer;
import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;

import static org.junit.Assert.assertEquals;
import java.util.function.Function;
import org.junit.Before;
import org.junit.Test;


public class TracingHelperTest {

Tracer mockTracer = new MockTracer();
private Tracer mockTracer = new MockTracer();
private MockSpan span;
private String prefix = "redis.";
Function<String, String> prefixSpanName;
TracingHelper helperWithProvider;
TracingHelper helperWithoutProvider;
private Function<String, String> prefixSpanName;
private TracingHelper helperWithProvider;
private TracingHelper helperWithoutProvider;

@Before
public void setUp() {
Expand Down
4 changes: 3 additions & 1 deletion opentracing-redis-jedis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>opentracing-redis-parent</artifactId>
<groupId>io.opentracing.contrib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import io.opentracing.contrib.redis.common.TracingHelper;
import java.net.URI;
import java.util.Arrays;
import java.util.function.Function;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Function;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocketFactory;
Expand Down Expand Up @@ -60,13 +60,13 @@
import redis.clients.util.Slowlog;



public class TracingJedis extends Jedis {

private final TracingHelper helper;
private Function<String, String> redisSpanNameProvider;

public TracingJedis(Tracer tracer, boolean traceWithActiveSpanOnly, Function<String, String> redisSpanNameProvider) {
public TracingJedis(Tracer tracer, boolean traceWithActiveSpanOnly,
Function<String, String> redisSpanNameProvider) {
super();
this.redisSpanNameProvider = redisSpanNameProvider;
this.helper = new TracingHelper(tracer, traceWithActiveSpanOnly, this.redisSpanNameProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Function;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Function;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.BinaryClient.LIST_POSITION;
import redis.clients.jedis.BinaryJedisPubSub;
Expand Down Expand Up @@ -56,7 +56,8 @@ public class TracingJedisCluster extends JedisCluster {
private final TracingHelper helper;
private Function<String, String> redisSpanNameProvider;

public TracingJedisCluster(HostAndPort node, Tracer tracer, boolean traceWithActiveSpanOnly, Function<String, String> redisSpanNameProvider) {
public TracingJedisCluster(HostAndPort node, Tracer tracer, boolean traceWithActiveSpanOnly,
Function<String, String> redisSpanNameProvider) {
super(node);
this.redisSpanNameProvider = redisSpanNameProvider;
this.helper = new TracingHelper(tracer, traceWithActiveSpanOnly, this.redisSpanNameProvider);
Expand Down Expand Up @@ -162,8 +163,10 @@ public TracingJedisCluster(Set<HostAndPort> jedisClusterNode, int timeout, int m
this.helper = new TracingHelper(tracer, traceWithActiveSpanOnly, redisSpanNameProvider);
}

public TracingJedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout, int soTimeout, int maxAttempts,
GenericObjectPoolConfig poolConfig, Tracer tracer, boolean traceWithActiveSpanOnly, Function<String, String> customSpanNameProvider) {
public TracingJedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout,
int soTimeout, int maxAttempts,
GenericObjectPoolConfig poolConfig, Tracer tracer, boolean traceWithActiveSpanOnly,
Function<String, String> customSpanNameProvider) {
super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, poolConfig);
this.redisSpanNameProvider = customSpanNameProvider;
this.helper = new TracingHelper(tracer, traceWithActiveSpanOnly, redisSpanNameProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
*/
package io.opentracing.contrib.redis.jedis;

import static org.junit.Assert.assertEquals;

import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.ThreadLocalScopeManager;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.embedded.RedisServer;

import java.util.List;

import static org.junit.Assert.assertEquals;

public class TracingJedisPoolTest {

private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@
*/
package io.opentracing.contrib.redis.jedis;

import static org.junit.Assert.assertEquals;

import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.ThreadLocalScopeManager;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.ThreadLocalScopeManager;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;
import redis.clients.jedis.Protocol;
import redis.embedded.RedisSentinel;
import redis.embedded.RedisServer;

import static org.junit.Assert.assertEquals;

public class TracingJedisSentinelPoolTest {

private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(), MockTracer.Propagator.TEXT_MAP);
private MockTracer mockTracer = new MockTracer(new ThreadLocalScopeManager(),
MockTracer.Propagator.TEXT_MAP);

private RedisServer redisServer;

Expand Down Expand Up @@ -69,7 +68,8 @@ public void after() {

@Test
public void testSentinelPoolReturnsTracedJedis() {
JedisSentinelPool pool = new TracingJedisSentinelPool(mockTracer, false, MASTER_NAME, sentinels, new GenericObjectPoolConfig());
JedisSentinelPool pool = new TracingJedisSentinelPool(mockTracer, false, MASTER_NAME, sentinels,
new GenericObjectPoolConfig());
Jedis jedis = pool.getResource();
assertEquals("OK", jedis.set("key", "value"));
assertEquals("value", jedis.get("key"));
Expand All @@ -82,7 +82,8 @@ public void testSentinelPoolReturnsTracedJedis() {

@Test
public void testClosingTracedJedisClosesUnderlyingJedis() {
JedisSentinelPool pool = new TracingJedisSentinelPool(mockTracer, false, MASTER_NAME, sentinels, new GenericObjectPoolConfig());
JedisSentinelPool pool = new TracingJedisSentinelPool(mockTracer, false, MASTER_NAME, sentinels,
new GenericObjectPoolConfig());
Jedis resource = pool.getResource();
assertEquals(1, pool.getNumActive());

Expand Down
4 changes: 3 additions & 1 deletion opentracing-redis-lettuce/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>opentracing-redis-parent</artifactId>
<groupId>io.opentracing.contrib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,24 @@
package io.opentracing.contrib.redis.lettuce;

import io.lettuce.core.RedisFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class CompletableRedisFuture<T> extends CompletableFuture<T> implements RedisFuture<T> {

private RedisFuture<T> wrappedFuture;
private RedisFuture<T> wrappedFuture;

public CompletableRedisFuture(RedisFuture<T> wrappedFuture) {
this.wrappedFuture = wrappedFuture;
}
public CompletableRedisFuture(RedisFuture<T> wrappedFuture) {
this.wrappedFuture = wrappedFuture;
}

@Override
public String getError() {
return wrappedFuture.getError();
}
@Override
public String getError() {
return wrappedFuture.getError();
}

@Override
public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
return wrappedFuture.await(timeout,unit);
}
@Override
public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
return wrappedFuture.await(timeout, unit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
import io.opentracing.Scope;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.redis.common.TracingHelper;
import io.opentracing.contrib.redis.common.RedisSpanNameProvider;
import io.opentracing.contrib.redis.common.TracingHelper;
import java.time.Duration;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -673,7 +673,7 @@ public RedisFuture<Long> decrby(K key, long amount) {
@Override
public RedisFuture<V> get(K key) {
Span span = helper.buildSpan("get", key);
return prepareRedisFuture(prepareRedisFuture(commands.get(key), span), span);
return prepareRedisFuture(commands.get(key), span);
}

@Override
Expand Down Expand Up @@ -745,7 +745,7 @@ public RedisFuture<Boolean> msetnx(Map<K, V> map) {
@Override
public RedisFuture<String> set(K key, V value) {
Span span = helper.buildSpan("set", key);
return prepareRedisFuture(prepareRedisFuture(commands.set(key, value), span), span);
return prepareRedisFuture(commands.set(key, value), span);
}

@Override
Expand Down Expand Up @@ -1934,7 +1934,8 @@ public RedisFuture<Long> zrevrangebyscoreWithScores(
Span span = helper.buildSpan("zrevrangebyscoreWithScores", key);
span.setTag("range", nullable(range));
span.setTag("limit", nullable(limit));
return prepareRedisFuture(commands.zrevrangebyscoreWithScores(channel, key, range, limit), span);
return prepareRedisFuture(commands.zrevrangebyscoreWithScores(channel, key, range, limit),
span);
}

@Override
Expand Down Expand Up @@ -2844,7 +2845,7 @@ public RedisFuture<String> unwatch() {
}

protected <V> RedisFuture<V> prepareRedisFuture(RedisFuture<V> future, Span span) {
return continueScopeSpan(setCompleteAction(future,span));
return continueScopeSpan(setCompleteAction(future, span));
}

protected <V> RedisFuture<V> setCompleteAction(RedisFuture<V> future, Span span) {
Expand All @@ -2858,11 +2859,11 @@ protected <V> RedisFuture<V> setCompleteAction(RedisFuture<V> future, Span span)
return future;
}

protected <T> RedisFuture<T> continueScopeSpan(RedisFuture<T> redisFuture){
protected <T> RedisFuture<T> continueScopeSpan(RedisFuture<T> redisFuture) {
Span span = tracer.activeSpan();
CompletableRedisFuture<T> customRedisFuture = new CompletableRedisFuture<>(redisFuture);
redisFuture.whenComplete((v, throwable) -> {
try (Scope ignored = tracer.scopeManager().activate(span,false)) {
try (Scope ignored = tracer.scopeManager().activate(span, false)) {
if (throwable != null) {
customRedisFuture.completeExceptionally(throwable);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
import io.lettuce.core.protocol.ProtocolKeyword;
import io.opentracing.Span;
import io.opentracing.Tracer;
import io.opentracing.contrib.redis.common.TracingHelper;
import io.opentracing.contrib.redis.common.RedisSpanNameProvider;
import io.opentracing.contrib.redis.common.TracingHelper;
import java.time.Duration;
import java.util.Arrays;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,21 @@ public void async() throws Exception {

@Test
public void async_continue_span() throws Exception {
try (Scope scope = mockTracer.buildSpan("test").startActive(true)){
try (Scope scope = mockTracer.buildSpan("test").startActive(true)) {
Span activeSpan = mockTracer.activeSpan();

RedisClient client = RedisClient.create("redis://localhost");

StatefulRedisConnection<String, String> connection =
new TracingStatefulRedisConnection<>(client.connect(), mockTracer, false);
new TracingStatefulRedisConnection<>(client.connect(), mockTracer, false);

RedisAsyncCommands<String, String> commands = connection.async();

assertEquals("OK",
commands.set("key2", "value2").toCompletableFuture().thenApply(s -> {
assertSame(activeSpan,mockTracer.activeSpan());
return s;
}).get(15, TimeUnit.SECONDS));
commands.set("key2", "value2").toCompletableFuture().thenApply(s -> {
assertSame(activeSpan, mockTracer.activeSpan());
return s;
}).get(15, TimeUnit.SECONDS));

connection.close();

Expand Down
Loading

0 comments on commit b6e9df4

Please sign in to comment.