Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ subprojects {

task packageSources(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource\
from sourceSets.main.allSource \

}
artifacts.archives packageSources
repositories {
Expand Down
3 changes: 2 additions & 1 deletion dd-java-agent-ittests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

public class SayTracedHello {

@Trace(operationName="SAY_HELLO")
public static String sayHello(){
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
return "hello!";
}
@Trace(operationName="SAY_HA")
public static String sayHA(){
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
new StringTag(DDTags.SPAN_TYPE).set(GlobalTracer.get().activeSpan(), "DB");
return "HA!!";
}
@Trace(operationName="NEW_TRACE")
public static String sayHELLOsayHA(){
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test2");
return sayHello()+sayHA();
}
@Trace(operationName = "SAY_HELLO")
public static String sayHello() {
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
return "hello!";
}

@Trace(operationName = "SAY_HA")
public static String sayHA() {
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test");
new StringTag(DDTags.SPAN_TYPE).set(GlobalTracer.get().activeSpan(), "DB");
return "HA!!";
}

@Trace(operationName = "NEW_TRACE")
public static String sayHELLOsayHA() {
new StringTag(DDTags.SERVICE_NAME).set(GlobalTracer.get().activeSpan(), "test2");
return sayHello() + sayHA();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,47 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.datadoghq.trace.agent.integration.AAgentIntegration;
import org.junit.Before;
import org.junit.Test;

import com.datadoghq.trace.agent.integration.AAgentIntegration;
public class TraceAnnotationsManagerTest extends AAgentIntegration {

@Before
public void beforeTest() throws Exception {
super.beforeTest();
}

@Test
public void testAnnotations() {
//Test single span in new trace
SayTracedHello.sayHello();

assertThat(writer.firstTrace().size()).isEqualTo(1);
assertThat(writer.firstTrace().get(0).getOperationName()).isEqualTo("SAY_HELLO");
assertThat(writer.firstTrace().get(0).getServiceName()).isEqualTo("test");

writer.start();

//Test new trace with 2 children spans
SayTracedHello.sayHELLOsayHA();
assertThat(writer.firstTrace().size()).isEqualTo(3);
long parentId = writer.firstTrace().get(0).context().getTraceId();

assertThat(writer.firstTrace().get(0).getOperationName()).isEqualTo("NEW_TRACE");
assertThat(writer.firstTrace().get(0).getParentId()).isEqualTo(0);//ROOT / no parent
assertThat(writer.firstTrace().get(0).context().getParentId()).isEqualTo(0);
assertThat(writer.firstTrace().get(0).getServiceName()).isEqualTo("test2");

assertThat(writer.firstTrace().get(1).getOperationName()).isEqualTo("SAY_HELLO");
assertThat(writer.firstTrace().get(1).getServiceName()).isEqualTo("test");
assertThat(writer.firstTrace().get(1).getParentId()).isEqualTo(parentId);

assertThat(writer.firstTrace().get(2).getOperationName()).isEqualTo("SAY_HA");
assertThat(writer.firstTrace().get(2).getParentId()).isEqualTo(parentId);
assertThat(writer.firstTrace().get(2).context().getSpanType()).isEqualTo("DB");

public class TraceAnnotationsManagerTest extends AAgentIntegration{

@Before
public void beforeTest() throws Exception {
super.beforeTest();
}

@Test
public void testAnnotations() {
//Test single span in new trace
SayTracedHello.sayHello();

assertThat(writer.firstTrace().size()).isEqualTo(1);
assertThat(writer.firstTrace().get(0).getOperationName()).isEqualTo("SAY_HELLO");
assertThat(writer.firstTrace().get(0).getServiceName()).isEqualTo("test");

writer.start();

//Test new trace with 2 children spans
SayTracedHello.sayHELLOsayHA();
assertThat(writer.firstTrace().size()).isEqualTo(3);
long parentId = writer.firstTrace().get(0).context().getTraceId();

assertThat(writer.firstTrace().get(0).getOperationName()).isEqualTo("NEW_TRACE");
assertThat(writer.firstTrace().get(0).getParentId()).isEqualTo(0);//ROOT / no parent
assertThat(writer.firstTrace().get(0).context().getParentId()).isEqualTo(0);
assertThat(writer.firstTrace().get(0).getServiceName()).isEqualTo("test2");

assertThat(writer.firstTrace().get(1).getOperationName()).isEqualTo("SAY_HELLO");
assertThat(writer.firstTrace().get(1).getServiceName()).isEqualTo("test");
assertThat(writer.firstTrace().get(1).getParentId()).isEqualTo(parentId);

assertThat(writer.firstTrace().get(2).getOperationName()).isEqualTo("SAY_HA");
assertThat(writer.firstTrace().get(2).getParentId()).isEqualTo(parentId);
assertThat(writer.firstTrace().get(2).context().getSpanType()).isEqualTo("DB");

writer.start();
}
writer.start();
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package com.datadoghq.trace.agent.integration;

import org.junit.Before;

import com.datadoghq.trace.DDTracer;
import com.datadoghq.trace.writer.ListWriter;

import io.opentracing.util.GlobalTracer;
import org.junit.Before;

public class AAgentIntegration {

protected static ListWriter writer = new ListWriter();
protected static DDTracer tracer = new DDTracer(writer);
protected static ListWriter writer = new ListWriter();
protected static DDTracer tracer = new DDTracer(writer);

@Before
public void beforeTest() throws Exception {
try {
GlobalTracer.register(tracer);
} catch (Exception e) {
//DO NOTHING IF ALREADY REGISTERED
}
writer.start();
}

@Before
public void beforeTest() throws Exception {
try{
GlobalTracer.register(tracer);
}catch(Exception e){
//DO NOTHING IF ALREADY REGISTERED
}
writer.start();
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.datadoghq.trace.agent.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import io.opentracing.contrib.aws.TracingRequestHandler;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class AWSInstrumentationTest {


@Test
public void test() {
@Test
public void test() {

// Build AWS client with TracingRequestHandler e.g.
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
builder.withRegion(Regions.US_EAST_1);
builder.build();
// Build AWS client with TracingRequestHandler e.g.
AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
builder.withRegion(Regions.US_EAST_1);
builder.build();

assertThat(builder.getRequestHandlers()).isNotNull();
assertThat(builder.getRequestHandlers().size()).isEqualTo(1);
assertThat(builder.getRequestHandlers().get(0).getClass()).isEqualTo(TracingRequestHandler.class);
}
assertThat(builder.getRequestHandlers()).isNotNull();
assertThat(builder.getRequestHandlers().size()).isEqualTo(1);
assertThat(builder.getRequestHandlers().get(0).getClass()).isEqualTo(TracingRequestHandler.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.datadoghq.trace.agent.integration;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentracing.contrib.apache.http.client.TracingHttpClientBuilder;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class ApacheHTTPClientTest extends AAgentIntegration {

@Test
public void test() throws Exception {
@Test
public void test() throws Exception {

HttpClientBuilder builder = HttpClientBuilder.create();
assertThat(builder).isInstanceOf(TracingHttpClientBuilder.class);
HttpClientBuilder builder = HttpClientBuilder.create();
assertThat(builder).isInstanceOf(TracingHttpClientBuilder.class);

// HttpClient client = builder.build();
// HttpGet request = new HttpGet("http://apache.org");
Expand All @@ -33,6 +33,6 @@ public void test() throws Exception {
// }

// assertThat(writer.firstTrace().size()).isEqualTo(2);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
package com.datadoghq.trace.agent.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.thrift.transport.TTransportException;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Created by gpolaert on 6/2/17.
*/
public class CassandraIntegrationTest {


@Before
public void start() throws InterruptedException, TTransportException, ConfigurationException, IOException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000L);
}
@Before
public void start() throws InterruptedException, TTransportException, ConfigurationException, IOException {
EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000L);
}

@After
public void stop() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}
@After
public void stop() {
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
}


@Test
public void testNewSessionSync() throws ClassNotFoundException {
Cluster cluster = EmbeddedCassandraServerHelper.getCluster();
Session session = cluster.newSession();
assertThat(session).isInstanceOf(Class.forName("io.opentracing.contrib.cassandra.TracingSession"));
@Test
public void testNewSessionSync() throws ClassNotFoundException {
Cluster cluster = EmbeddedCassandraServerHelper.getCluster();
Session session = cluster.newSession();
assertThat(session).isInstanceOf(Class.forName("io.opentracing.contrib.cassandra.TracingSession"));


}
}

@Test
public void testNewSessionAsync() throws ClassNotFoundException, ExecutionException, InterruptedException {
Cluster cluster = EmbeddedCassandraServerHelper.getCluster();
Session session = cluster.connectAsync().get();
assertThat(session).isInstanceOf(Class.forName("io.opentracing.contrib.cassandra.TracingSession"));
@Test
public void testNewSessionAsync() throws ClassNotFoundException, ExecutionException, InterruptedException {
Cluster cluster = EmbeddedCassandraServerHelper.getCluster();
Session session = cluster.connectAsync().get();
assertThat(session).isInstanceOf(Class.forName("io.opentracing.contrib.cassandra.TracingSession"));


}
}
}
Loading