Skip to content

Commit

Permalink
[HWKMETRICS-200] fix REST API test for counter rates
Browse files Browse the repository at this point in the history
Now that the rates job is scheduled per tenant during tenant creation, the test
needs to explicitly create the tenant.

I also updated the createTenant method to concat the observable returned from
scheduling the task with the index updates. This way the subscriber will be
notified if any of the updates, along with scheduling the rates task, fails.
  • Loading branch information
John Sanda committed Aug 12, 2015
1 parent 9076871 commit a4ed252
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void setTaskScheduler(TaskScheduler taskScheduler) {
@Override
public Observable<Void> createTenant(final Tenant tenant) {
return Observable.create(subscriber -> {
Observable<ResultSet> updates = dataAccess.insertTenant(tenant).flatMap(resultSet -> {
Observable<Void> updates = dataAccess.insertTenant(tenant).flatMap(resultSet -> {
if (!resultSet.wasApplied()) {
throw new TenantAlreadyExistsException(tenant.getId());
}
Expand All @@ -328,14 +328,17 @@ public Observable<Void> createTenant(final Tenant tenant) {
.withInterval(1, TimeUnit.MINUTES)
.build();
Map<String, String> params = ImmutableMap.of("tenant", tenant.getId());
taskScheduler.scheduleTask("generate-rates", tenant.getId(), 100, params, trigger);
Observable<Void> ratesScheduled = taskScheduler.scheduleTask("generate-rates", tenant.getId(),
100, params, trigger).map(task -> null);

return Observable.from(tenant.getRetentionSettings().entrySet())
Observable<Void> retentionUpdates = Observable.from(tenant.getRetentionSettings().entrySet())
.flatMap(entry -> dataAccess.updateRetentionsIndex(tenant.getId(), entry.getKey(),
ImmutableMap.of(makeSafe(entry.getKey().getText()), entry.getValue())));
ImmutableMap.of(makeSafe(entry.getKey().getText()), entry.getValue())))
.map(rs -> null);

return ratesScheduled.concatWith(retentionUpdates);
});
updates.subscribe(resultSet -> {
}, subscriber::onError, subscriber::onCompleted);
updates.subscribe(resultSet -> {}, subscriber::onError, subscriber::onCompleted);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,10 @@ class CountersITest extends RESTTest {

setTime(start)

// Create the counter metric
// Create the tenant
def response = hawkularMetrics.post(
path: "counters",
headers: [(tenantHeaderName): tenantId],
body: [id: counter]
path: "tenants",
body: [id: tenantId]
)
assertEquals(201, response.status)

Expand Down

0 comments on commit a4ed252

Please sign in to comment.