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 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
@@ -0,0 +1,60 @@
/*
* 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;

import java.util.HashMap;

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");
HashMap<Integer,SpanId> spanIdHashMap = new HashMap<>();
SpanId parentID = new SpanId(100L, 200L);
spanIdHashMap.put(activeScope.getSpanId().hashCode(),activeScope.getSpanId());
spanIdHashMap.put(parentID.hashCode(),parentID);
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);
//parent on index 0
Assert.assertNotNull(spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()));
Assert.assertEquals(childScope.getSpan().getParents()[0].getHigh(),
spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getHigh());
Assert.assertEquals(childScope.getSpan().getParents()[0].getLow(),
spanIdHashMap.get(childScope.getSpan().getParents()[0].hashCode()).getLow());
//parent on index 1
Assert.assertNotNull(spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()));
Assert.assertEquals(childScope.getSpan().getParents()[1].getHigh(),
spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getHigh());
Assert.assertEquals(childScope.getSpan().getParents()[1].getLow(),
spanIdHashMap.get(childScope.getSpan().getParents()[1].hashCode()).getLow());
childScope.close();
activeScope.close();

}
}