Skip to content

Commit e2e0199

Browse files
author
nsahai8
committed
improvising
1 parent 65f7fd7 commit e2e0199

File tree

7 files changed

+27
-22
lines changed

7 files changed

+27
-22
lines changed

core/src/main/java/com/expedia/www/haystack/client/Tracer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.expedia.www.haystack.client;
1818

1919
import com.expedia.www.haystack.client.dispatchers.Dispatcher;
20+
import com.expedia.www.haystack.client.idgenerators.IdGenerator;
21+
import com.expedia.www.haystack.client.idgenerators.LongIdGenerator;
2022
import com.expedia.www.haystack.client.metrics.*;
2123
import com.expedia.www.haystack.client.metrics.Timer;
2224
import com.expedia.www.haystack.client.metrics.Timer.Sample;

core/src/main/java/com/expedia/www/haystack/client/IdGenerator.java renamed to core/src/main/java/com/expedia/www/haystack/client/idgenerators/IdGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
package com.expedia.www.haystack.client;
17+
package com.expedia.www.haystack.client.idgenerators;
1818

1919
public interface IdGenerator {
2020
Object generate();

core/src/main/java/com/expedia/www/haystack/client/LongIdGenerator.java renamed to core/src/main/java/com/expedia/www/haystack/client/idgenerators/LongIdGenerator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
package com.expedia.www.haystack.client;
17+
package com.expedia.www.haystack.client.idgenerators;
1818

1919

20+
import com.expedia.www.haystack.client.idgenerators.IdGenerator;
21+
2022
import java.util.concurrent.ThreadLocalRandom;
2123

2224
public class LongIdGenerator implements IdGenerator {

core/src/main/java/com/expedia/www/haystack/client/UUIDv4Generator.java renamed to core/src/main/java/com/expedia/www/haystack/client/idgenerators/RandomUUIDGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
package com.expedia.www.haystack.client;
17+
package com.expedia.www.haystack.client.idgenerators;
18+
1819

1920
import java.util.UUID;
2021

21-
public class UUIDv4Generator implements IdGenerator {
22+
public class RandomUUIDGenerator implements IdGenerator {
2223

2324
@Override
2425
public UUID generate() {

core/src/main/java/com/expedia/www/haystack/client/UUIDv3Generator.java renamed to core/src/main/java/com/expedia/www/haystack/client/idgenerators/TimeBasedUUIDGenerator.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,16 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
package com.expedia.www.haystack.client;
17+
package com.expedia.www.haystack.client.idgenerators;
1818

19-
import com.fasterxml.uuid.Generators;
20-
import com.fasterxml.uuid.NoArgGenerator;
2119

22-
public class UUIDv3Generator implements IdGenerator {
20+
import com.fasterxml.uuid.Generators;
2321

24-
private final NoArgGenerator generator ;
2522

26-
UUIDv3Generator(String type){
27-
generator = type.equals("time")? Generators.timeBasedGenerator(): Generators.randomBasedGenerator();
28-
}
23+
public class TimeBasedUUIDGenerator implements IdGenerator {
2924

3025
@Override
3126
public Object generate() {
32-
return generator.generate();
27+
return Generators.timeBasedGenerator().generate();
3328
}
3429
}

core/src/test/java/com/expedia/www/haystack/client/SpanBuilderTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.expedia.www.haystack.client.dispatchers.Dispatcher;
2020
import com.expedia.www.haystack.client.dispatchers.NoopDispatcher;
21+
import com.expedia.www.haystack.client.idgenerators.RandomUUIDGenerator;
2122
import com.expedia.www.haystack.client.metrics.NoopMetricsRegistry;
2223
import com.expedia.www.haystack.client.propagation.MapBackedTextMap;
2324
import io.opentracing.References;
@@ -67,7 +68,7 @@ public void testChildOfWithDualSpanType() {
6768
//create a client span
6869
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
6970
"ClientService",
70-
dispatcher).withDualSpanMode().withIdGenerator(new UUIDv4Generator()).build();
71+
dispatcher).withDualSpanMode().withIdGenerator(new RandomUUIDGenerator()).build();
7172
final Span clientSpan = clientTracer.buildSpan("Api_call")
7273
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
7374
.start();
@@ -77,7 +78,7 @@ public void testChildOfWithDualSpanType() {
7778
//create a server
7879
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
7980
"ServerService",
80-
dispatcher).withDualSpanMode().withIdGenerator(new UUIDv4Generator()).build();
81+
dispatcher).withDualSpanMode().withIdGenerator(new RandomUUIDGenerator()).build();
8182
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
8283
final Span serverSpan = serverTracer.buildSpan("Api")
8384
.asChildOf(wireContext)
@@ -97,7 +98,7 @@ public void testChildOfWithSingleSpanType() {
9798
//create a client span
9899
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
99100
"ClientService",
100-
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
101+
dispatcher).withIdGenerator(new RandomUUIDGenerator()).build();
101102
final Span clientSpan = clientTracer.buildSpan("Api_call")
102103
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
103104
.start();
@@ -107,7 +108,7 @@ public void testChildOfWithSingleSpanType() {
107108
//create a server
108109
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
109110
"ServerService",
110-
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
111+
dispatcher).withIdGenerator(new RandomUUIDGenerator()).build();
111112
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
112113
final Span serverSpan = serverTracer.buildSpan("Api")
113114
.asChildOf(wireContext)
@@ -128,7 +129,7 @@ public void testChildOfWithSingleSpanTypeAndExtractedContext() {
128129
//create a client span
129130
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
130131
"ClientService",
131-
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
132+
dispatcher).withIdGenerator(new RandomUUIDGenerator()).build();
132133

133134
final Span clientSpan = clientTracer.buildSpan("Api_call")
134135
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
@@ -158,7 +159,7 @@ public void testChildOfSingleSpanTypeWithExtractedContextDoesNotPropagateExtract
158159
//create a client span
159160
final Tracer clientTracer = new Tracer.Builder(new NoopMetricsRegistry(),
160161
"ClientService",
161-
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
162+
dispatcher).withIdGenerator(new RandomUUIDGenerator()).build();
162163
final Span clientSpan = clientTracer.buildSpan("Api_call")
163164
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT)
164165
.start();
@@ -168,7 +169,7 @@ public void testChildOfSingleSpanTypeWithExtractedContextDoesNotPropagateExtract
168169
//create a server
169170
final Tracer serverTracer = new Tracer.Builder(new NoopMetricsRegistry(),
170171
"ServerService",
171-
dispatcher).withIdGenerator(new UUIDv4Generator()).build();
172+
dispatcher).withIdGenerator(new RandomUUIDGenerator()).build();
172173
final SpanContext wireContext = serverTracer.extract(Format.Builtin.TEXT_MAP, wireData);
173174
final Span serverSpan = serverTracer.buildSpan("Api")
174175
.asChildOf(wireContext)

core/src/test/java/com/expedia/www/haystack/client/TracerBuildTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
package com.expedia.www.haystack.client;
1818

1919
import com.expedia.www.haystack.client.dispatchers.NoopDispatcher;
20+
import com.expedia.www.haystack.client.idgenerators.IdGenerator;
21+
import com.expedia.www.haystack.client.idgenerators.LongIdGenerator;
22+
import com.expedia.www.haystack.client.idgenerators.RandomUUIDGenerator;
23+
import com.expedia.www.haystack.client.idgenerators.TimeBasedUUIDGenerator;
2024
import com.expedia.www.haystack.client.metrics.NoopMetricsRegistry;
2125
import org.junit.Assert;
2226
import org.junit.Test;
@@ -44,7 +48,7 @@ public void testTracerBuildWithoutIdGenerator(){
4448

4549
@Test
4650
public void testTracerBuildUUIDv3IdGenerator(){
47-
IdGenerator idGenerator = new UUIDv3Generator("time");
51+
IdGenerator idGenerator = new TimeBasedUUIDGenerator();
4852
Tracer.Builder tracerBuild = new Tracer.Builder(new NoopMetricsRegistry(), "TestTracer", new NoopDispatcher());
4953
tracerBuild.withIdGenerator(idGenerator);
5054
Tracer tracer = tracerBuild.build();
@@ -53,7 +57,7 @@ public void testTracerBuildUUIDv3IdGenerator(){
5357

5458
@Test
5559
public void testTracerBuildUUIDv4IdGenerator(){
56-
IdGenerator idGenerator = new UUIDv4Generator();
60+
IdGenerator idGenerator = new RandomUUIDGenerator();
5761
Tracer.Builder tracerBuild = new Tracer.Builder(new NoopMetricsRegistry(), "TestTracer", new NoopDispatcher());
5862
tracerBuild.withIdGenerator(idGenerator);
5963
Tracer tracer = tracerBuild.build();

0 commit comments

Comments
 (0)