|
| 1 | +/* |
| 2 | + * Copyright 2018 Expedia, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.expedia.www.haystack.trace.reader.readers.utils |
| 17 | + |
| 18 | +import java.lang.System.currentTimeMillis |
| 19 | + |
| 20 | +import com.expedia.open.tracing.Span |
| 21 | +import com.expedia.open.tracing.Tag |
| 22 | +import com.expedia.www.haystack.trace.reader.readers.utils.SpanMarkers.SERVICE_TAG_KEY |
| 23 | +import com.expedia.www.haystack.trace.reader.unit.BaseUnitTestSpec |
| 24 | + |
| 25 | +class SpanUtilsSpec extends BaseUnitTestSpec { |
| 26 | + val ServiceNameInAttribute: String = currentTimeMillis + "ServiceNameInAttribute" |
| 27 | + val ServiceNameInTag: String = currentTimeMillis + "ServiceNameInTag" |
| 28 | + |
| 29 | + describe("SpanUtils object, getEffectiveServiceName() method") { |
| 30 | + it("should return the span's service name if the 'service' tag is not found") { |
| 31 | + val span = Span.newBuilder().setServiceName(ServiceNameInAttribute).build |
| 32 | + val serviceName = SpanUtils.getEffectiveServiceName(span) |
| 33 | + assert(serviceName == ServiceNameInAttribute) |
| 34 | + } |
| 35 | + |
| 36 | + it("should return the tag's service name if the 'service' tag has a non-null value") { |
| 37 | + val tag = Tag.newBuilder().setKey(SERVICE_TAG_KEY).setVStr(ServiceNameInTag).build |
| 38 | + val span = Span.newBuilder().setServiceName(ServiceNameInAttribute).addTags(tag).build |
| 39 | + val serviceName = SpanUtils.getEffectiveServiceName(span) |
| 40 | + assert(serviceName == ServiceNameInTag) |
| 41 | + } |
| 42 | + |
| 43 | + it("should return the span's service name if the 'service' tag has no value") { |
| 44 | + val tag = Tag.newBuilder().setKey(SERVICE_TAG_KEY).build |
| 45 | + val span = Span.newBuilder().setServiceName(ServiceNameInAttribute).addTags(tag).build |
| 46 | + val serviceName = SpanUtils.getEffectiveServiceName(span) |
| 47 | + assert(serviceName == ServiceNameInAttribute) |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments