Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
Add throttler proxy test
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Hier committed Jul 9, 2018
1 parent 73de332 commit b6c96b9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import java.util.List;

@Path("")
public class MockAgentResource {
Expand All @@ -44,4 +45,24 @@ public String getBaggageRestrictions(@QueryParam("service") String serviceName)
}
throw new WebApplicationException();
}

@GET
@Path("credits")
@Produces(MediaType.APPLICATION_JSON)
public String getCredits(@QueryParam("uuid") int clientId,
@QueryParam("service") String serviceName,
@QueryParam("operations") List<String> operations) {
if (serviceName.equals("clairvoyant")) {
StringBuffer buffer = new StringBuffer("{ \"balances\": [");
for (int i = 0; i < operations.size(); i++) {
if (i > 0) {
buffer.append(", ");
}
buffer.append("{ \"operation\": \"" + operations.get(i) + "\", \"balance\": 1 }");
}
buffer.append("]}");
return buffer.toString();
}
throw new WebApplicationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.uber.jaeger.throttler;

import com.uber.jaeger.mocks.MockAgentResource;
import com.uber.jaeger.throttler.http.CreditResponse;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.glassfish.jersey.test.TestProperties;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.ws.rs.core.Application;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class HttpThrottlerProxyTest extends JerseyTest {
private static Properties originalProps;
private static final int CLIENT_ID = 1234;
private static final String OPERATION_NAME = "test-operation";

private HttpThrottlerProxy proxy;

@BeforeClass
public static void beforeClass() {
originalProps = new Properties(System.getProperties());
if (System.getProperty(TestProperties.CONTAINER_PORT) == null) {
System.setProperty(TestProperties.CONTAINER_PORT, "0");
}
}

@AfterClass
public static void afterClass() {
System.setProperties(originalProps);
}

@Override
protected Application configure() {

return new ResourceConfig(MockAgentResource.class);
}

@Test
public void testGetCredits() throws Exception {
URI uri = target().getUri();
proxy = new HttpThrottlerProxy(uri.getHost() + ":" + uri.getPort());
final List<String> operations = new ArrayList<String>();
operations.add(OPERATION_NAME);
CreditResponse response = proxy.getCredits(CLIENT_ID, "clairvoyant", operations);
assertNotNull(response);
assertEquals(1, response.getBalances().size());
assertEquals(OPERATION_NAME, response.getBalances().get(0).getOperation());
assertEquals(1, response.getBalances().get(0).getBalance(), 0.0001);

try {
proxy.getCredits(CLIENT_ID, "invalid-service", operations);
} catch (ThrottlerException e) {
return;
}

assert(false);
}
}

0 comments on commit b6c96b9

Please sign in to comment.