Skip to content

Instantly share code, notes, and snippets.

View jsanda's full-sized avatar

John Sanda jsanda

View GitHub Profile
BigDecimal.metaClass.equals = { return compareTo(it); }
class TestScriptBase {
@Override
Object run() {
return null
}
def execute() {
BigDecimal.metaClass.equals = { return true }
script()
}
@jsanda
jsanda / gist:702b82b06222ded41aad
Created April 2, 2015 14:58
add data end point
public void addDataForMetric(
@Suspended final AsyncResponse asyncResponse,
@PathParam("tenantId") final String tenantId, @PathParam("id") String id,
@ApiParam(value = "List of datapoints containing timestamp and value", required = true)
List<NumericData> data
) {
Callable<Response> callable = () -> {
// long sleep = random.nextLong() % SLEEP;
// if (sleep > 0) {
// try {
@Path("/")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public class AsyncHandler {
private static final ListeningExecutorService threadPool = MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(4));
@POST
@Path("/{tenantId}/metrics/numeric/{id}/data")
Observable<Lease> leaseObservable = leaseService.find(timeSlice)
.filter(lease -> lease.getOwner() == null)
.map(lease -> lease.setOwner(owner));
Observable<Boolean> acquiredObservable = leaseObservable.flatMap(leaseService::acquire)
.filter(acquired -> acquired);
Observable.zip(leaseObservable, acquiredObservable, ((lease, acquired) -> lease))
.flatMap(lease -> findTasks(lease, taskType))
.map(executeTasksSegment)
.flatMap(this::rescheduleTask)
.flatMap(taskContainer -> rxSession.execute(queries.deleteTasks.bind(
public class StateListenerTest {
private static final Log logger = LogFactory.getLog(StateListenerTest.class);
@Test
public void listenForStateChanges() throws Exception {
Cluster cluster = new ClusterBuilder()
.addContactPoints("127.0.0.1")
.withCredentials("rhqadmin", "rhqadmin")
.build();
public class MetricsServiceProducer {
private MetricsServiceImpl metricsService;
@Produces
public MetricsService getMetricsService() {
if (metricsService == null) {
metricsService = new MetricsServiceImpl();
Session session = // create session object...
String keyspace = // keyspace to use for metrics...
@Test
public void findAvg() throws Exception {
DateTime start = now().minusMinutes(30);
DateTime end = start.plusMinutes(20);
String tenantId = "t1";
metricsService.createTenant(new Tenant(tenantId)).toBlocking().lastOrDefault(null);
Metric<Double> m1 = new Metric<>(tenantId, GAUGE, new MetricId("m1"), asList(
new DataPoint<>(start.getMillis(), 1.1),
static class MinMax {
public DataPoint<Double> min;
public DataPoint<Double> max;
}
@Test
public void findRange() throws Exception {
DateTime start = now().minusMinutes(30);
DateTime end = start.plusMinutes(20);
String tenantId = "t1";
public <T> T applyFunction(String tenantId, MetricId id, long start, long end,
Func1<Observable<DataPoint<Double>>, T> function) {
Observable<DataPoint<Double>> dataPoints = metricsService.findGaugeData(tenantId, id, start, end);
return function.call(dataPoints);
}
@Test
public void getAverage() {
DateTime start = now().minusMinutes(30);
DateTime end = start.plusMinutes(20);