Skip to content
Permalink
Browse files
Merge pull request #97 from isururanawaka/test_framework
add testFetchMetadata
  • Loading branch information
isururanawaka committed May 20, 2022
2 parents e81929c + 5394a63 commit ef9146664dc7c78eb2483d4f9c039e2c86f7ce0e
Showing 1 changed file with 69 additions and 0 deletions.
@@ -296,6 +296,75 @@ public String testCreateResource(@RequestParam("username") String username,



}



@RequestMapping(value = "/testFetchMetadata", method = RequestMethod.GET)
@ResponseBody
public String testFetchMetadata(@RequestParam("username") String username,
@RequestParam("tenantId") String tenantId,
@RequestParam("totalIterations") int iterations,
@RequestParam("reportChunkSize") int reportChunkSize,
@RequestParam("filePath") String filePath,
@RequestParam("entityId") String resourceId) {


ManagedChannel channel = ManagedChannelBuilder.forAddress(serviceHost, servicePort).usePlaintext().build();
ResourceServiceGrpc.ResourceServiceBlockingStub resourceClient = ResourceServiceGrpc.newBlockingStub(channel);



int successRequests = 0;
int failureRequests = 0;
long sum = 0;

Map<String, String> latencyMap = new HashMap<>();

int chunkSize = 1;

for (int i = 0; i < iterations; i++) {
try {
long beginLatency = System.currentTimeMillis();
FetchResourceMetadataRequest request = FetchResourceMetadataRequest
.newBuilder()
.setAuthToken(DRMSServiceAuthToken.newBuilder()
.setAuthenticatedUser(AuthenticatedUser.newBuilder()
.setTenantId(tenantId)
.setUsername(username)
.build()))
.setResourceId(resourceId)
.build();
FetchResourceMetadataResponse response = resourceClient.fetchResourceMetadata(request);
long endLatency = System.currentTimeMillis();

long diff = endLatency - beginLatency;
latencyMap.put(String.valueOf(i), String.valueOf(diff));
sum += diff;
if (response.getMetadataCount()!= 0) {
successRequests++;
}
} catch (Exception ex) {
failureRequests++;
}

if (chunkSize % reportChunkSize == 0) {
long avgSuccessRate = (successRequests / chunkSize) * 100;
long avgFailureRare = (failureRequests / chunkSize) * 100;

writeToAFile(latencyMap, avgSuccessRate, avgFailureRare, filePath, "testResourceCreateRequest");
latencyMap.clear();
successRequests = 0;
failureRequests = 0;
chunkSize = 1;
} else {
chunkSize++;
}
}
return "load test completed";



}


0 comments on commit ef91466

Please sign in to comment.