Search in sources :

Example 1 with PerTenantConfig

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);
}
Also used : PerTenantConfig(org.killbill.billing.util.config.tenant.PerTenantConfig) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with PerTenantConfig

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();
}
Also used : TenantContext(org.killbill.billing.util.callcontext.TenantContext) PerTenantConfig(org.killbill.billing.util.config.tenant.PerTenantConfig) Function(com.google.common.base.Function) VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) Tenant(org.killbill.billing.tenant.api.Tenant) Nullable(javax.annotation.Nullable) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with PerTenantConfig

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));
}
Also used : PerTenantConfig(org.killbill.billing.util.config.tenant.PerTenantConfig) Tenant(org.killbill.billing.client.model.gen.Tenant) StateMachineConfig(org.killbill.automaton.StateMachineConfig) List(java.util.List) OverdueConfig(org.killbill.billing.overdue.api.OverdueConfig) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

PerTenantConfig (org.killbill.billing.util.config.tenant.PerTenantConfig)3 Test (org.testng.annotations.Test)2 Function (com.google.common.base.Function)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 File (java.io.File)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 StateMachineConfig (org.killbill.automaton.StateMachineConfig)1 VersionedCatalog (org.killbill.billing.catalog.api.VersionedCatalog)1 Tenant (org.killbill.billing.client.model.gen.Tenant)1 OverdueConfig (org.killbill.billing.overdue.api.OverdueConfig)1 Tenant (org.killbill.billing.tenant.api.Tenant)1 TenantContext (org.killbill.billing.util.callcontext.TenantContext)1 ObjectMapper (org.killbill.billing.util.jackson.ObjectMapper)1