Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

adding test case for HTRACE-363 #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.htrace.core;

import org.junit.Assert;
import org.junit.Test;

public class TestNewScopeWithParentID {

@Test
public void testNewScopeWithParentID() throws Exception {

Tracer tracer = new Tracer.Builder().
name("testNewScopeWithParentID").
tracerPool(new TracerPool("testNewScopeWithParentID")).
conf(HTraceConfiguration.fromKeyValuePairs(
"sampler.classes", "AlwaysSampler")).build();
TraceScope activeScope = tracer.newScope("CurrentActiveScope");
SpanId parentID = new SpanId(100L, 200L);
TraceScope childScope = tracer.
newScope("ChildScope", parentID);
Assert.assertNotNull(childScope);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use the form of assert that takes a descriptive message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review. I will add those.

Assert.assertEquals(childScope.getSpan().getParents().length, 2);
Assert.assertEquals(childScope.getSpan().getParents()[1].getHigh(), 100L);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Would prefer comparing against parentId.getHigh()

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the order guaranteed? I'm not sure that it is, rather than being an implementation detail in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I debugged the code it always goes through this lines looks like there is order at least for this two parent case,

private TraceScope newScopeImpl(ThreadContext context, String description,
TraceScope parentScope, SpanId secondParentId) {
SpanId parentId = parentScope.getSpan().getSpanId();
Span span = new MilliSpan.Builder().
tracerId(tracerId).
begin(System.currentTimeMillis()).
description(description).
parents(new SpanId[] { parentId, secondParentId }).
spanId(parentId.newChildId()).
build();
return context.pushNewScope(this, span, parentScope);
}

Assert.assertEquals(childScope.getSpan().getParents()[1].getLow(), 200L);
//SpanID generated by invoking fromRandom()
Assert.assertNotNull(childScope.getSpan().getParents()[0].getHigh());
Assert.assertNotNull(childScope.getSpan().getParents()[0].getLow());
Assert.assertEquals(childScope.getSpan().getParents()[0].getHigh(),
activeScope.getSpan().getSpanId().getHigh());
Assert.assertEquals(childScope.getSpan().getParents()[0].getLow(),
activeScope.getSpan().getSpanId().getLow());

}
}