use of org.killbill.billing.util.config.tenant.PerTenantConfig in project killbill by killbill.
the class TestCacheConfig method testDeSerialization.
@Test(groups = "fast")
public void testDeSerialization() throws Exception {
final ObjectMapper objectMapper = new ObjectMapper();
final PerTenantConfig input = new PerTenantConfig();
input.put("key1", "foo");
input.put("key2", "bar");
input.put("key3", "34346");
input.put("key4", "23.999");
final String inputString = objectMapper.writeValueAsString(input);
final PerTenantConfig result = objectMapper.readValue(inputString, PerTenantConfig.class);
Assert.assertEquals(result.size(), 4);
}
use of org.killbill.billing.util.config.tenant.PerTenantConfig in project killbill by killbill.
the class AdminResource method invalidatesCacheByTenant.
@DELETE
@Path("/" + CACHE + "/" + TENANTS)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Invalidates Caches per tenant level")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Successful operation") })
public Response invalidatesCacheByTenant(@javax.ws.rs.core.Context final HttpServletRequest request) throws TenantApiException {
// creating Tenant Context from Request
final TenantContext tenantContext = context.createTenantContextNoAccountId(request);
final Tenant currentTenant = tenantApi.getTenantById(tenantContext.getTenantId());
// getting Tenant Record Id
final Long tenantRecordId = recordIdApi.getRecordId(tenantContext.getTenantId(), ObjectType.TENANT, tenantContext);
final Function<String, Boolean> tenantKeysMatcher = new Function<String, Boolean>() {
@Override
public Boolean apply(@Nullable final String key) {
return key != null && key.endsWith("::" + tenantRecordId);
}
};
// clear tenant-record-id cache by tenantId
final CacheController<String, Long> tenantRecordIdCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID);
tenantRecordIdCacheController.remove(currentTenant.getId().toString());
// clear tenant-payment-state-machine-config cache by tenantRecordId
final CacheController<String, Object> tenantPaymentStateMachineConfigCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT_PAYMENT_STATE_MACHINE_CONFIG);
tenantPaymentStateMachineConfigCacheController.remove(tenantKeysMatcher);
// clear tenant cache by tenantApiKey
final CacheController<String, Tenant> tenantCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT);
tenantCacheController.remove(currentTenant.getApiKey());
// clear tenant-kv cache by tenantRecordId
final CacheController<String, String> tenantKVCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT_KV);
tenantKVCacheController.remove(tenantKeysMatcher);
// clear tenant-config cache by tenantRecordId
final CacheController<Long, PerTenantConfig> tenantConfigCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT_CONFIG);
tenantConfigCacheController.remove(tenantRecordId);
// clear tenant-overdue-config cache by tenantRecordId
final CacheController<Long, Object> tenantOverdueConfigCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT_OVERDUE_CONFIG);
tenantOverdueConfigCacheController.remove(tenantRecordId);
// clear tenant-catalog cache by tenantRecordId
final CacheController<Long, VersionedCatalog> tenantCatalogCacheController = cacheControllerDispatcher.getCacheController(CacheType.TENANT_CATALOG);
tenantCatalogCacheController.remove(tenantRecordId);
return Response.status(Status.NO_CONTENT).build();
}
use of org.killbill.billing.util.config.tenant.PerTenantConfig in project killbill by killbill.
the class TestCache method testInvalidateCacheByTenant.
@Test(groups = "slow", description = "Can Invalidate (clear) all Tenant Caches for current Tenant")
public void testInvalidateCacheByTenant() throws Exception {
// creating a new Tenant for this test
final Tenant currentTenant = createTenant("testApiKey", "testApiSecret", false);
// Uploading the test catalog using the new Tenant created before
callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
final String catalogPath = Resources.getResource("SpyCarAdvanced.xml").getPath();
final File catalogFile = new File(catalogPath);
final String body = Files.toString(catalogFile, Charset.forName("UTF-8"));
catalogApi.uploadCatalogXml(body, requestOptions);
callbackServlet.assertListenerStatus();
// creating an Account with PaymentMethod and a Subscription
createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice("Sports", true);
// get all caches per tenant level
final CacheController<String, Long> tenantRecordIdCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID);
final CacheController<String, StateMachineConfig> tenantPaymentStateMachineConfigCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_PAYMENT_STATE_MACHINE_CONFIG);
final CacheController<String, org.killbill.billing.tenant.api.Tenant> tenantCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT);
final CacheController<String, String> tenantKvCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_KV);
final CacheController<Long, PerTenantConfig> tenantConfigCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_CONFIG);
final CacheController<Long, OverdueConfig> tenantOverdueConfigCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_OVERDUE_CONFIG);
final CacheController<Long, List<StaticCatalog>> tenantCatalogCache = cacheControllerDispatcher.getCacheController(CacheType.TENANT_CATALOG);
// verify that they are not null and have the expected tenant information
assertTrue(tenantRecordIdCache.isKeyInCache(currentTenant.getTenantId().toString()));
final Long tenantRecordId = tenantRecordIdCache.get(currentTenant.getTenantId().toString(), null);
assertTrue(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
assertTrue(tenantCache.isKeyInCache(currentTenant.getApiKey()));
assertTrue(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
assertTrue(tenantConfigCache.isKeyInCache(tenantRecordId));
assertTrue(tenantOverdueConfigCache.isKeyInCache(tenantRecordId));
assertTrue(tenantCatalogCache.isKeyInCache(tenantRecordId));
// invalidate caches per tenant level
adminApi.invalidatesCache(null, requestOptions);
// verify that now the caches don't have the previous values
assertFalse(tenantRecordIdCache.isKeyInCache(currentTenant.getTenantId().toString()));
assertFalse(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
assertFalse(tenantCache.isKeyInCache(currentTenant.getApiKey()));
assertFalse(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
assertFalse(tenantConfigCache.isKeyInCache(tenantRecordId));
assertFalse(tenantOverdueConfigCache.isKeyInCache(tenantRecordId));
assertFalse(tenantCatalogCache.isKeyInCache(tenantRecordId));
}
Aggregations