Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagohora committed Sep 13, 2024
1 parent be2be34 commit 7c0eab2
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

@ImplementedBy(FeedbackScoreServiceImpl.class)
public interface FeedbackScoreService {
Flux<FeedbackScore> getScores(EntityType entityType, UUID entityId);

Mono<Void> scoreTrace(UUID traceId, FeedbackScore score);
Mono<Void> scoreSpan(UUID spanId, FeedbackScore score);
Expand Down Expand Up @@ -66,12 +65,6 @@ class FeedbackScoreServiceImpl implements FeedbackScoreService {
record ProjectDto(Project project, List<FeedbackScoreBatchItem> scores) {
}

@Override
public Flux<FeedbackScore> getScores(@NonNull EntityType entityType, @NonNull UUID entityId) {
return asyncTemplate.nonTransaction(connection -> dao.getScores(entityType, List.of(entityId), connection))
.flatMapIterable(entityIdToFeedbackScoresMap -> entityIdToFeedbackScoresMap.get(entityId));
}

@Override
public Mono<Void> scoreTrace(@NonNull UUID traceId, @NonNull FeedbackScore score) {
return lockService.executeWithLock(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.comet.opik.api.resources.utils;

import lombok.experimental.UtilityClass;

import java.net.URI;
import java.util.UUID;

@UtilityClass
public class TestUtils {

public static UUID getIdFromLocation(URI location) {
return UUID.fromString(location.getPath().substring(location.getPath().lastIndexOf('/') + 1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.comet.opik.api.resources.utils.MySQLContainerUtils;
import com.comet.opik.api.resources.utils.RedisContainerUtils;
import com.comet.opik.api.resources.utils.TestDropwizardAppExtensionUtils;
import com.comet.opik.api.resources.utils.TestUtils;
import com.comet.opik.api.resources.utils.WireMockUtils;
import com.comet.opik.domain.FeedbackScoreMapper;
import com.comet.opik.podam.PodamFactoryUtils;
Expand Down Expand Up @@ -195,8 +196,7 @@ private UUID createAndAssert(Dataset dataset, String apiKey, String workspaceNam
assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);
assertThat(actualResponse.hasEntity()).isFalse();

var id = UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
var id = TestUtils.getIdFromLocation(actualResponse.getLocation());

assertThat(id).isNotNull();
assertThat(id.version()).isEqualTo(7);
Expand Down Expand Up @@ -2532,8 +2532,7 @@ private UUID createTrace(Trace trace, String apiKey, String workspaceName) {
.post(Entity.entity(trace, MediaType.APPLICATION_JSON_TYPE))) {
assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);

return UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
return TestUtils.getIdFromLocation(actualResponse.getLocation());
}
}

Expand All @@ -2545,8 +2544,7 @@ private UUID createSpan(Span span, String apiKey, String workspaceName) {
.post(Entity.entity(span, MediaType.APPLICATION_JSON_TYPE))) {
assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);

return UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
return TestUtils.getIdFromLocation(actualResponse.getLocation());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.comet.opik.api.resources.utils.MySQLContainerUtils;
import com.comet.opik.api.resources.utils.RedisContainerUtils;
import com.comet.opik.api.resources.utils.TestDropwizardAppExtensionUtils;
import com.comet.opik.api.resources.utils.TestUtils;
import com.comet.opik.api.resources.utils.WireMockUtils;
import com.comet.opik.domain.FeedbackScoreMapper;
import com.comet.opik.podam.PodamFactoryUtils;
Expand Down Expand Up @@ -1536,8 +1537,7 @@ private UUID createAndAssert(Experiment expectedExperiment, String apiKey, Strin

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);

var path = actualResponse.getLocation().getPath();
var actualId = UUID.fromString(path.substring(path.lastIndexOf('/') + 1));
var actualId = TestUtils.getIdFromLocation(actualResponse.getLocation());

assertThat(actualResponse.hasEntity()).isFalse();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.comet.opik.api.resources.utils.MySQLContainerUtils;
import com.comet.opik.api.resources.utils.RedisContainerUtils;
import com.comet.opik.api.resources.utils.TestDropwizardAppExtensionUtils;
import com.comet.opik.api.resources.utils.TestUtils;
import com.comet.opik.api.resources.utils.WireMockUtils;
import com.comet.opik.podam.PodamFactoryUtils;
import com.fasterxml.uuid.Generators;
Expand Down Expand Up @@ -135,8 +136,7 @@ private UUID create(final FeedbackDefinition<?> feedback, String apiKey, String

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);

return UUID.fromString(actualResponse.getLocation().getPath()
.substring(actualResponse.getLocation().getPath().lastIndexOf('/') + 1));
return TestUtils.getIdFromLocation(actualResponse.getLocation());
}
}

Expand Down Expand Up @@ -848,9 +848,7 @@ void create() {
assertThat(actualResponse.hasEntity()).isFalse();
assertThat(actualResponse.getHeaderString("Location")).matches(Pattern.compile(URL_PATTERN));

id = UUID.fromString(actualResponse.getLocation().getPath()
.substring(actualResponse.getLocation().getPath().lastIndexOf('/') + 1));

id = TestUtils.getIdFromLocation(actualResponse.getLocation());
}

var actualResponse = client.target(URL_TEMPLATE.formatted(baseURI))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.comet.opik.api.resources.utils.MySQLContainerUtils;
import com.comet.opik.api.resources.utils.RedisContainerUtils;
import com.comet.opik.api.resources.utils.TestDropwizardAppExtensionUtils;
import com.comet.opik.api.resources.utils.TestUtils;
import com.comet.opik.api.resources.utils.WireMockUtils;
import com.comet.opik.podam.PodamFactoryUtils;
import com.github.tomakehurst.wiremock.client.WireMock;
Expand Down Expand Up @@ -134,8 +135,7 @@ private UUID createProject(Project project, String apiKey, String workspaceName)

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);

return UUID.fromString(actualResponse.getLocation().getPath()
.substring(actualResponse.getLocation().getPath().lastIndexOf('/') + 1));
return TestUtils.getIdFromLocation(actualResponse.getLocation());
}
}

Expand Down Expand Up @@ -820,8 +820,7 @@ void create() {

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);
assertThat(actualResponse.hasEntity()).isFalse();
id = UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
id = TestUtils.getIdFromLocation(actualResponse.getLocation());
}

assertProject(project.toBuilder().id(id)
Expand All @@ -848,8 +847,7 @@ void create__whenWorkspaceNameIsSpecified__thenAcceptTheRequest() {

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);
assertThat(actualResponse.hasEntity()).isFalse();
id = UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
id = TestUtils.getIdFromLocation(actualResponse.getLocation());

}

Expand Down Expand Up @@ -932,8 +930,7 @@ void create__whenProjectsHaveSameNameButDifferentWorkspace__thenAcceptTheRequest

assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);
assertThat(actualResponse.hasEntity()).isFalse();
id = UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
id = TestUtils.getIdFromLocation(actualResponse.getLocation());
}

var project2 = project1.toBuilder()
Expand All @@ -950,8 +947,7 @@ void create__whenProjectsHaveSameNameButDifferentWorkspace__thenAcceptTheRequest
assertThat(actualResponse.getStatusInfo().getStatusCode()).isEqualTo(201);
assertThat(actualResponse.hasEntity()).isFalse();

id2 = UUID.fromString(actualResponse.getHeaderString("Location")
.substring(actualResponse.getHeaderString("Location").lastIndexOf('/') + 1));
id2 = TestUtils.getIdFromLocation(actualResponse.getLocation());
}

assertProject(project1.toBuilder().id(id).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.comet.opik.api.resources.utils.MySQLContainerUtils;
import com.comet.opik.api.resources.utils.RedisContainerUtils;
import com.comet.opik.api.resources.utils.TestDropwizardAppExtensionUtils;
import com.comet.opik.api.resources.utils.TestUtils;
import com.comet.opik.api.resources.utils.WireMockUtils;
import com.comet.opik.domain.SpanMapper;
import com.comet.opik.domain.SpanType;
Expand Down Expand Up @@ -3092,7 +3093,7 @@ private UUID createAndAssert(Span expectedSpan, String apiKey, String workspaceN
if (expectedSpan.id() != null) {
expectedSpanId = expectedSpan.id();
} else {
expectedSpanId = UUID.fromString(actualHeaderString.substring(actualHeaderString.lastIndexOf('/') + 1));
expectedSpanId = TestUtils.getIdFromLocation(actualResponse.getLocation());
}

assertThat(actualHeaderString).isEqualTo(URL_TEMPLATE.formatted(baseURI)
Expand Down
Loading

0 comments on commit 7c0eab2

Please sign in to comment.