Skip to content

Commit

Permalink
Fixed some unused imports and added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWittmann committed Sep 13, 2024
1 parent 9552546 commit c1543ed
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.slf4j.Logger;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.apicurio.registry.AbstractResourceTestBase;
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
import io.apicurio.registry.rest.v2.beans.GroupMetaData;
import io.apicurio.registry.rest.v2.beans.SortBy;
import io.apicurio.registry.rest.v2.beans.SortOrder;
import io.apicurio.registry.types.ArtifactType;
Expand All @@ -18,9 +17,6 @@
import java.util.Set;
import java.util.concurrent.CountDownLatch;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;

@QuarkusTest
public class ConcurrentCreateTest extends AbstractResourceTestBase {

Expand Down Expand Up @@ -81,4 +77,60 @@ public void testMultipleArtifacts() throws Exception {

}

@Test
public void testSameArtifact() throws Exception {
String oaiArtifactContent = resourceToString("openapi-empty.json");
String groupId = TestUtils.generateGroupId();

Set<String> created = new HashSet<>();
Set<String> failed = new HashSet<>();
CountDownLatch latch = new CountDownLatch(5);

// Try to create the SAME artifact 5 times.
for (int i = 0; i < 5; i++) {
final int forkId = i;
TestUtils.fork(() -> {
String artifactId = "test-artifact";
System.out.println("[Fork-" + forkId + "] Starting");
try {
InputStream data = new ByteArrayInputStream(oaiArtifactContent.getBytes());

// Create the artifact
ArtifactMetaData amd = clientV2.createArtifact(groupId, artifactId, ArtifactType.OPENAPI, data);
System.out.println("[Fork-" + forkId + "] Artifact created.");
Assertions.assertNotNull(amd);
Assertions.assertEquals(groupId, amd.getGroupId());
Assertions.assertEquals(artifactId, amd.getId());

// Fetch the artifact and make sure it really got created.
amd = clientV2.getArtifactMetaData(groupId, artifactId);
Assertions.assertNotNull(amd);
Assertions.assertEquals(groupId, amd.getGroupId());
Assertions.assertEquals(artifactId, amd.getId());

System.out.println("[Fork-" + forkId + "] Completed successfully.");
created.add("" + forkId);
} catch (Exception e) {
System.out.println("[Fork-" + forkId + "] FAILED: " + e.getMessage());
failed.add("" + forkId);
}
latch.countDown();
});
}

latch.await();

Assertions.assertEquals(4, failed.size());
Assertions.assertEquals(1, created.size());

ArtifactSearchResults results = clientV2.searchArtifacts(groupId, null, null, null, null, SortBy.createdOn, SortOrder.asc, 0, 100);
Assertions.assertNotNull(results);
Assertions.assertEquals(1, results.getCount());

results = clientV2.listArtifactsInGroup(groupId);
Assertions.assertNotNull(results);
Assertions.assertEquals(1, results.getCount());

}

}

0 comments on commit c1543ed

Please sign in to comment.