@Override public CassandraEndpointNotification save(EndpointNotificationDto dto) { CassandraEndpointNotification endpointNotification = new CassandraEndpointNotification(dto); LOG.debug("Save endpoint notification for endpoint profile {}", Utils.encodeHexString(endpointNotification.getEndpointKeyHash())); save(new CassandraEndpointNotification(dto)); LOG.trace("Saved endpoint notification {}", endpointNotification); return endpointNotification; }
@Override public CassandraEndpointNotification findById(String id) { LOG.debug("Try to find endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Select.Where where = select().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); LOG.debug("[{}] Execute query {}:", id, where); CassandraEndpointNotification endpointNotification = findOneByStatement(where); LOG.trace("Found endpoint notification {} by id {}:", endpointNotification, id); return endpointNotification; }
@Test public void testSave() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 1).get(0); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertEquals(1, found.size()); }
@Override public void removeById(String id) { LOG.debug("Remove endpoint notifications by id {}", id); CassandraEndpointNotification key = new CassandraEndpointNotification(id); Statement delete = delete().from(getColumnFamilyName()) .where(eq(ET_NF_ENDPOINT_KEY_HASH_PROPERTY, key.getEndpointKeyHash())) .and(eq(ET_NF_LAST_MOD_TIME_PROPERTY, key.getLastModifyTime())); execute(delete); LOG.debug("[{}] Execute query {}:", id, delete); }
@Test public void testFindNotificationsByKeyHash() throws Exception { List<CassandraEndpointNotification> notifications = generateEndpointNotification(null, 1); generateEndpointNotification(null, 2); CassandraEndpointNotification notification = notifications.get(0); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertEquals(notifications.size(), found.size()); }
@Test public void testRemoveNotificationsByAppId() throws Exception { CassandraEndpointNotification notification = generateEndpointNotification(null, 3).get(0); String appId = notification.getApplicationId(); unicastNotificationDao.removeNotificationsByAppId(appId); List<CassandraEndpointNotification> found = unicastNotificationDao.findNotificationsByKeyHash(notification.getEndpointKeyHash().array()); Assert.assertTrue(found.isEmpty()); }