Skip to content
Merged
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
2 changes: 1 addition & 1 deletion hypertrace-trace-enricher/trace-reader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
compileOnly("org.projectlombok:lombok:1.18.20")

testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
testImplementation("org.mockito:mockito-core:3.8.0")
testImplementation("org.mockito:mockito-inline:3.8.0")
testImplementation("org.mockito:mockito-junit-jupiter:3.8.0")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.14.1")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static java.util.function.Predicate.not;

import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.schedulers.Schedulers;
import java.time.Duration;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -61,20 +62,21 @@ public void writeAssociatedEntitiesForSpanEventually(StructuredTrace trace, Even
}

private void writeEntityIfExists(EntityType entityType, StructuredTrace trace, Event span) {
Entity entity = this.buildEntity(entityType, trace, span).blockingGet();
if (entity == null) {
return;
}
UpsertCondition upsertCondition =
this.buildUpsertCondition(entityType, trace, span)
.defaultIfEmpty(UpsertCondition.getDefaultInstance())
.blockingGet();

this.entityDataClient.createOrUpdateEntityEventually(
RequestContext.forTenantId(this.traceAttributeReader.getTenantId(span)),
entity,
upsertCondition,
this.writeThrottleDuration);
this.buildEntity(entityType, trace, span)
.subscribeOn(Schedulers.io())
.subscribe(
entity -> {
UpsertCondition upsertCondition =
this.buildUpsertCondition(entityType, trace, span)
.defaultIfEmpty(UpsertCondition.getDefaultInstance())
.blockingGet();

this.entityDataClient.createOrUpdateEntityEventually(
RequestContext.forTenantId(this.traceAttributeReader.getTenantId(span)),
entity,
upsertCondition,
this.writeThrottleDuration);
});
}

private Maybe<UpsertCondition> buildUpsertCondition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import static org.mockito.Mockito.when;

import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.schedulers.Schedulers;
import java.time.Duration;
import java.util.Arrays;
import java.util.Map;
Expand All @@ -37,11 +39,14 @@
import org.hypertrace.entity.type.service.v2.EntityType;
import org.hypertrace.entity.type.service.v2.EntityType.EntityFormationCondition;
import org.hypertrace.trace.reader.attributes.TraceAttributeReader;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
Expand Down Expand Up @@ -105,18 +110,27 @@ class DefaultTraceEntityAccessorTest {
@Mock EntityDataClient mockDataClient;
@Mock CachingAttributeClient mockAttributeClient;
@Mock TraceAttributeReader<StructuredTrace, Event> mockAttributeReader;
MockedStatic<Schedulers> mockSchedulers;

private DefaultTraceEntityAccessor entityAccessor;

@BeforeEach
void beforeEach() {
Scheduler trampoline = Schedulers.trampoline();
this.entityAccessor =
new DefaultTraceEntityAccessor(
this.mockTypeClient,
this.mockDataClient,
this.mockAttributeClient,
this.mockAttributeReader,
DEFAULT_DURATION);
mockSchedulers = Mockito.mockStatic(Schedulers.class);
mockSchedulers.when(Schedulers::io).thenReturn(trampoline);
}

@AfterEach
void afterEach() {
mockSchedulers.close();
}

@Test
Expand All @@ -126,7 +140,6 @@ void canWriteAllEntities() {
mockTenantId();
mockAttributeRead(TEST_ENTITY_ID_ATTRIBUTE, stringLiteral(TEST_ENTITY_ID_ATTRIBUTE_VALUE));
mockAttributeRead(TEST_ENTITY_NAME_ATTRIBUTE, stringLiteral(TEST_ENTITY_NAME_ATTRIBUTE_VALUE));

this.entityAccessor.writeAssociatedEntitiesForSpanEventually(TEST_TRACE, TEST_SPAN);

verify(mockDataClient, times(1))
Expand Down