Created
May 9, 2014 12:45
-
-
Save jsanda/0904eed46d338d7df457 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ServerTest extends MetricsTest { | |
private static final int TTL = 360; | |
private PlatformManager platformManager; | |
private DataAccess dataAccess; | |
private RawMetricMapper rawMapper; | |
@BeforeClass | |
public void startModule() throws Exception { | |
final CountDownLatch moduleDeployed = new CountDownLatch(1); | |
final AtomicReference<Throwable> cause = new AtomicReference<Throwable>(); | |
JsonObject config = new JsonObject() | |
.putString("keyspace", getKeyspace()); | |
platformManager = PlatformLocator.factory.createPlatformManager(); | |
String moduleName = "org.rhq.metrics~rhq-metrics-rest~0.1.0-SNAPSHOT"; | |
platformManager.deployModule(moduleName, config, 1, new Handler<AsyncResult<String>>() { | |
public void handle(AsyncResult<String> result) { | |
if (result.failed()) { | |
cause.set(result.cause()); | |
result.cause().printStackTrace(); | |
} | |
moduleDeployed.countDown(); | |
} | |
}); | |
moduleDeployed.await(); | |
assertNull(cause.get(), "Deployment of " + moduleName + " failed"); | |
initSession(); | |
dataAccess = new DataAccess(session); | |
rawMapper = new RawMetricMapper(); | |
} | |
@Test | |
public void test1() { | |
} | |
@AfterClass | |
public void stopModule() { | |
platformManager.stop(); | |
} | |
@BeforeMethod | |
public void initMethod() { | |
resetDB(); | |
} | |
@Test | |
public void findRawMetricsForSingleId() throws Exception { | |
final String metricId = UUID.randomUUID().toString(); | |
long timestamp1 = System.currentTimeMillis(); | |
double value1 = 2.17; | |
ResultSetFuture insertFuture = dataAccess.insertData("raw", metricId, timestamp1, | |
ImmutableMap.of(DataType.RAW.ordinal(), value1), TTL); | |
// wait for the insert to finish | |
getUninterruptibly(insertFuture); | |
long timestamp2 = timestamp1 - 2500; | |
double value2 = 2.4567; | |
insertFuture = dataAccess.insertData("raw", metricId, timestamp2, ImmutableMap.of(DataType.RAW.ordinal(), | |
value2), TTL); | |
// wait for insert to finish | |
getUninterruptibly(insertFuture); | |
final CountDownLatch responseReceived = new CountDownLatch(1); | |
final Buffer buffer = new Buffer(); | |
final HttpClient httpClient = platformManager.vertx().createHttpClient().setPort(7474); | |
platformManager.vertx().runOnContext(new Handler<Void>() { | |
@Override | |
public void handle(Void event) { | |
httpClient.getNow("/rhq-metrics/" + metricId + "/data", new Handler<HttpClientResponse>() { | |
public void handle(HttpClientResponse response) { | |
response.bodyHandler(new Handler<Buffer>() { | |
public void handle(Buffer content) { | |
buffer.appendBuffer(content); | |
responseReceived.countDown(); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment