Skip to content

Commit

Permalink
refactors tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishekkr3003 committed Nov 10, 2023
1 parent ec950dc commit 14f1109
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public List<TypeInstrumentation> typeInstrumentations() {
return asList(
new SyncCommandInstrumentation(),
new SocketInstrumentation(),
new TransferSizeIntrumentation(),
new AsyncCommandInstrumentation(),
new AsyncHandlerInstrumentation(),
new AsyncScanAllCommandInstrumentation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ public static void stopSpan(
} else {
request.setStatus(Status.SUCCESS);
}
if (record == null || record.bins.isEmpty()) {
request.setSize(0);
} else {
int size = 0;
for (Object value : record.bins.values()) {
size += ((String) value).length();
}
request.setSize(size);
}
if (scope == null) {
return;
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;

import com.aerospike.client.AerospikeClient;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.async.EventLoops;
import com.aerospike.client.async.EventPolicy;
import com.aerospike.client.async.NioEventLoops;
Expand All @@ -31,7 +33,7 @@
import org.testcontainers.containers.wait.strategy.Wait;

@SuppressWarnings("deprecation") // until old http semconv are dropped in 2.0
class AerospikeClientAsyncCommandTest {
class AerospikeClientTest {
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

Expand Down Expand Up @@ -71,7 +73,7 @@ void setup() {
}

@Test
void putCommand() {
void asyncCommand() {
Key aerospikeKey = new Key("test", "test-set", "data1");
aerospikeClient.put(null, null, null, aerospikeKey, new Bin("bin1", "value1"));

Expand All @@ -97,27 +99,48 @@ void putCommand() {
}

@Test
void getCommand() {
Key aerospikeKey = new Key("test", "test-set", "data1");
List<String> bins = singletonList("bin1");
aerospikeClient.get(null, null, null, aerospikeKey, bins.toArray(new String[0]));
void syncCommand() {
Key aerospikeKey = new Key("test", "test-set", "data2");
aerospikeClient.put(null, aerospikeKey, new Bin("bin2", "value2"));
List<String> bins = singletonList("bin2");
Record aerospikeRecord = aerospikeClient.get(null, aerospikeKey, bins.toArray(new String[0]));
assertThat(aerospikeRecord.getString("bin2")).isEqualTo("value2");

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("ASYNCREAD")
span.hasName("PUT")
.hasKind(SpanKind.CLIENT)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"),
equalTo(SemanticAttributes.DB_OPERATION, "ASYNCREAD"),
equalTo(SemanticAttributes.DB_OPERATION, "PUT"),
equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port),
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data1"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data2"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0),
satisfies(
SemanticAttributes.NET_SOCK_PEER_NAME,
val -> val.isIn("localhost", "127.0.0.1")))),
trace ->
trace.hasSpansSatisfyingExactly(
span ->
span.hasName("GET")
.hasKind(SpanKind.CLIENT)
.hasAttributesSatisfyingExactly(
equalTo(SemanticAttributes.DB_SYSTEM, "aerospike"),
equalTo(SemanticAttributes.DB_OPERATION, "GET"),
equalTo(SemanticAttributes.NET_SOCK_PEER_PORT, port),
equalTo(SemanticAttributes.NET_SOCK_PEER_ADDR, "127.0.0.1"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_NAMESPACE, "test"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_SET_NAME, "test-set"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_USER_KEY, "data2"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_STATUS, "SUCCESS"),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_ERROR_CODE, 0),
equalTo(AerospikeSemanticAttributes.AEROSPIKE_TRANSFER_SIZE, 6),
satisfies(
SemanticAttributes.NET_SOCK_PEER_NAME,
val -> val.isIn("localhost", "127.0.0.1")))));
Expand Down

0 comments on commit 14f1109

Please sign in to comment.