Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 The OpenTracing Authors
* Copyright 2016-2017 The OpenTracing Authors
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making license plugin happy.

(PR editing MockSpan was created in 2016 and merged in 2017).

*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 The OpenTracing Authors
* Copyright 2016-2017 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -173,6 +173,9 @@ public Tracer.SpanBuilder withStartTimestamp(long microseconds) {

@Override
public Span start() {
if (this.startMicros == 0) {
this.startMicros = MockSpan.nowMicros();
}
return new MockSpan(MockTracer.this, this.operationName, this.startMicros, initialTags, this.firstParent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 The OpenTracing Authors
* Copyright 2016-2017 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -13,15 +13,17 @@
*/
package io.opentracing.mock;

import io.opentracing.Span;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import org.junit.Assert;
import org.junit.Test;

import io.opentracing.Span;

public class MockTracerTest {
@Test
Expand Down Expand Up @@ -99,4 +101,38 @@ public void testChildSpan() {
assertEquals(parent.context().spanId(), child.parentId());
assertEquals(parent.context().traceId(), child.context().traceId());
}

@Test
public void testStartTimestamp() throws InterruptedException {
MockTracer tracer = new MockTracer();
long startMicros;
{
MockTracer.SpanBuilder fooSpan = tracer.buildSpan("foo");
Thread.sleep(2);
startMicros = System.currentTimeMillis() * 1000;
fooSpan.start().finish();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why extra scope?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just minimizing sope. It's used in other tests in this file.

List<MockSpan> finishedSpans = tracer.finishedSpans();

Assert.assertEquals(1, finishedSpans.size());
MockSpan span = finishedSpans.get(0);
Assert.assertTrue(startMicros <= span.startMicros());
Assert.assertTrue(System.currentTimeMillis() * 1000 >= span.finishMicros());
}

@Test
public void testStartExplicitTimestamp() throws InterruptedException {
MockTracer tracer = new MockTracer();
long startMicros = 2000;
{
tracer.buildSpan("foo")
.withStartTimestamp(startMicros)
.start()
.finish();
}
List<MockSpan> finishedSpans = tracer.finishedSpans();

Assert.assertEquals(1, finishedSpans.size());
Assert.assertEquals(startMicros, finishedSpans.get(0).startMicros());
}
}