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
BigDecimal.metaClass.equals = { return compareTo(it); } |
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
class TestScriptBase { | |
@Override | |
Object run() { | |
return null | |
} | |
def execute() { | |
BigDecimal.metaClass.equals = { return true } | |
script() | |
} |
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 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 { |
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
@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") |
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
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( |
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 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(); |
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 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... |
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
@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), |
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
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"; |
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 <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); |