Search in sources :

Example 1 with EntitySqlDaoTransactionalJdbiWrapper

use of org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper in project killbill by killbill.

the class TestDefaultOverdueCheckPoster method beforeMethod.

@Override
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
    if (hasFailed()) {
        return;
    }
    super.beforeMethod();
    entitySqlDaoTransactionalJdbiWrapper = new EntitySqlDaoTransactionalJdbiWrapper(dbi, roDbi, clock, cacheControllerDispatcher, nonEntityDao, internalCallContextFactory);
    overdueQueue = notificationQueueService.getNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE);
    Assert.assertTrue(overdueQueue.isStarted());
    testReferenceTime = clock.getUTCNow();
}
Also used : EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with EntitySqlDaoTransactionalJdbiWrapper

use of org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper in project killbill by killbill.

the class TestCache method testAllCachesAfterGetById.

@Test(groups = "slow")
public void testAllCachesAfterGetById() throws Exception {
    this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, roDbi, clock, controlCacheDispatcher, nonEntityDao, internalCallContextFactory);
    final TagModelDao tag = new TagModelDao(clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID(), ObjectType.TAG);
    insertTag(tag);
    // Verify we start with nothing in the cache
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 0);
    Assert.assertEquals(getCacheSize(CacheType.ACCOUNT_RECORD_ID), 0);
    Assert.assertEquals(getCacheSize(CacheType.TENANT_RECORD_ID), 0);
    Assert.assertEquals(getCacheSize(CacheType.OBJECT_ID), 0);
    final TagModelDao result = getById(tag.getId());
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 1);
    Assert.assertEquals(getCacheSize(CacheType.ACCOUNT_RECORD_ID), 1);
    Assert.assertEquals(getCacheSize(CacheType.TENANT_RECORD_ID), 1);
    Assert.assertEquals(getCacheSize(CacheType.OBJECT_ID), 1);
    final Long recordId = (Long) controlCacheDispatcher.getCacheController(CacheType.RECORD_ID).get(tag.getId().toString(), new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(recordId, result.getRecordId());
    final Long tenantRecordId = (Long) controlCacheDispatcher.getCacheController(CacheType.TENANT_RECORD_ID).get(tag.getId().toString(), new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(tenantRecordId, result.getTenantRecordId());
    final UUID objectId = (UUID) controlCacheDispatcher.getCacheController(CacheType.OBJECT_ID).get(TableName.TAG + CacheControllerDispatcher.CACHE_KEY_SEPARATOR + recordId, new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(objectId, result.getId());
    final Long accountRecordId = (Long) controlCacheDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID).get(tag.getId().toString(), new CacheLoaderArgument(ObjectType.TAG));
    Assert.assertEquals(accountRecordId, result.getAccountRecordId());
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 3 with EntitySqlDaoTransactionalJdbiWrapper

use of org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper in project killbill by killbill.

the class TestEntityBaseDaoException method testWithCreateException.

@Test(groups = "slow")
public void testWithCreateException() throws Exception {
    final EntitySqlDaoTransactionalJdbiWrapper entitySqlDaoTransactionalJdbiWrapper = new EntitySqlDaoTransactionalJdbiWrapper(dbi, roDbi, clock, null, nonEntityDao, null);
    final TestEntityBaseDao test = new TestEntityBaseDao(nonEntityDao, entitySqlDaoTransactionalJdbiWrapper, KombuchaSqlDao.class);
    final KombuchaModelDao entity = new KombuchaModelDao() {

        @Override
        public Long getRecordId() {
            return null;
        }

        @Override
        public Long getAccountRecordId() {
            return null;
        }

        @Override
        public Long getTenantRecordId() {
            return null;
        }

        @Override
        public TableName getTableName() {
            return null;
        }

        @Override
        public TableName getHistoryTableName() {
            return null;
        }

        @Override
        public UUID getId() {
            return null;
        }

        @Override
        public DateTime getCreatedDate() {
            return null;
        }

        @Override
        public DateTime getUpdatedDate() {
            return null;
        }
    };
    try {
        test.create(entity, internalCallContext);
        Assert.fail("test should throw SecurityApiException");
    } catch (final SecurityApiException e) {
        Assert.assertEquals(e.getCode(), ErrorCode.__UNKNOWN_ERROR_CODE.getCode());
    }
}
Also used : EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) SecurityApiException(org.killbill.billing.security.SecurityApiException) Test(org.testng.annotations.Test)

Example 4 with EntitySqlDaoTransactionalJdbiWrapper

use of org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper in project killbill by killbill.

the class TestCache method testCacheRecordId.

@Test(groups = "slow")
public void testCacheRecordId() throws Exception {
    this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, roDbi, clock, controlCacheDispatcher, nonEntityDao, internalCallContextFactory);
    final TagModelDao tag = new TagModelDao(clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID(), ObjectType.TAG);
    // Verify we start with nothing in the cache
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 0);
    insertTag(tag);
    // Verify we still have nothing after insert in the cache
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 0);
    final Long tagRecordId = tagDao.getRecordId(tag);
    // Verify we now have something  in the cache
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 1);
    final Long recordIdFromCache = retrieveRecordIdFromCache(tag.getId());
    Assert.assertNotNull(recordIdFromCache);
    Assert.assertEquals(recordIdFromCache, tagRecordId);
    // We cannot assume the number to be 1 here as the auto_increment implementation
    // depends on the database.
    // See also http://h2database.com/html/grammar.html#create_sequence
    Assert.assertTrue(recordIdFromCache > 0);
    Assert.assertEquals(getCacheSize(CacheType.RECORD_ID), 1);
}
Also used : TagModelDao(org.killbill.billing.util.tag.dao.TagModelDao) EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) Test(org.testng.annotations.Test)

Example 5 with EntitySqlDaoTransactionalJdbiWrapper

use of org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper in project killbill by killbill.

the class TestInvoiceDaoHelper method setUp.

@BeforeMethod(groups = "slow")
public void setUp() throws Exception {
    if (hasFailed()) {
        return;
    }
    account = invoiceUtil.createAccount(callContext);
    now = clock.getNow(account.getTimeZone());
    today = now.toLocalDate();
    internalAccountContext = internalCallContextFactory.createInternalCallContext(account.getId(), callContext);
    transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, roDbi, clock, cacheControllerDispatcher, nonEntityDao, internalCallContextFactory);
}
Also used : EntitySqlDaoTransactionalJdbiWrapper(org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

EntitySqlDaoTransactionalJdbiWrapper (org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper)6 BeforeMethod (org.testng.annotations.BeforeMethod)3 Test (org.testng.annotations.Test)3 TagModelDao (org.killbill.billing.util.tag.dao.TagModelDao)2 UUID (java.util.UUID)1 Account (org.killbill.billing.account.api.Account)1 AccountData (org.killbill.billing.account.api.AccountData)1 SecurityApiException (org.killbill.billing.security.SecurityApiException)1 CacheControllerDispatcher (org.killbill.billing.util.cache.CacheControllerDispatcher)1