use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class HBaseNotificationStoreIntegrationTest method testGetNotifications.
@Test
public void testGetNotifications() throws Exception {
List<Notification> notifications = NotificationTestObjectFactory.getMany(10);
for (Notification notification : notifications) {
sut.store(notification);
}
List<Notification> fetchedNotifications = sut.getNotifications(Lists.transform(notifications, new Function<Notification, String>() {
@Nullable
@Override
public String apply(@Nullable Notification notification) {
return notification.getId();
}
}));
assertEquals(notifications, fetchedNotifications);
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class HBaseScanConfigBuilderTest method testGetScanConfig.
@Test
public void testGetScanConfig() throws Exception {
final List<Criteria.Field> fr = new ArrayList<>();
fr.add(new CriteriaImpl.FieldImpl("notifierName", "test_notifier"));
fr.add(new CriteriaImpl.FieldImpl("status", "NEW"));
final List<byte[]> nnList = Arrays.asList("s".getBytes(CHARSET), "qs".getBytes(CHARSET), "NEW".getBytes(CHARSET));
new Expectations() {
{
mockNotificationCriteria.clazz();
times = 1;
result = Notification.class;
mockNotificationCriteria.fieldRestrictions();
times = 1;
result = fr;
mockIndexMapper.getIndexedFieldNames();
times = 1;
result = Arrays.asList("notifierName");
mockNotificationCriteria.numRows();
times = 1;
result = 5;
mockIndexMapper.mapMemberValue("status", "NEW");
times = 1;
result = nnList;
}
};
hBaseScanConfigBuilder = new HBaseScanConfigBuilder();
hBaseScanConfigBuilder.addMappers(Notification.class, Arrays.asList(mockIndexMapper));
Criteria<Notification> eventCriteria = new CriteriaImpl<>(Notification.class);
HBaseScanConfig<Notification> notificationScanConfig = hBaseScanConfigBuilder.getScanConfig(mockNotificationCriteria);
System.out.println(notificationScanConfig);
assertEquals(mockIndexMapper, notificationScanConfig.getMapper());
assertArrayEquals("test_notifier|0".getBytes(CHARSET), notificationScanConfig.getStartRow());
assertArrayEquals(("test_notifier|" + Long.MAX_VALUE).getBytes(CHARSET), notificationScanConfig.getStopRow());
assertEquals(2, notificationScanConfig.filterList().getFilters().size());
// column filter should be first
Filter firstFilter = notificationScanConfig.filterList().getFilters().get(0);
assertEquals(SingleColumnValueFilter.class, firstFilter.getClass());
// page filter should be last
Filter secondFilter = notificationScanConfig.filterList().getFilters().get(1);
assertEquals(PageFilter.class, secondFilter.getClass());
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class NotificationMapperTest method testEntity.
@Test
public void testEntity() throws Exception {
final Map<byte[], byte[]> tsMap = new TreeMap<>(new Bytes.ByteArrayComparator());
tsMap.put("1444042473518".getBytes(), "1".getBytes());
new Expectations() {
{
mockResult.getRow();
times = 1;
result = "nid-1".getBytes();
mockResult.getValue("s".getBytes(), "qs".getBytes());
times = 1;
result = "DELIVERED".getBytes();
mockResult.getFamilyMap("ts".getBytes());
times = 1;
result = tsMap;
}
};
Notification notification = notificationMapper.entity(mockResult);
// System.out.println(notification);
assertEquals(notification.getId(), "nid-1");
assertEquals(notification.getStatus(), Notification.Status.DELIVERED);
assertEquals(notification.getTs(), 1444042473518L);
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class NotificationBoltTest method testAck.
@Test
public void testAck() throws Exception {
Map<String, Object> fieldsAndValues = new HashMap<>();
fieldsAndValues.put("temperature", "100");
final StreamlineEvent event = StreamlineEventImpl.builder().fieldsAndValues(fieldsAndValues).dataSourceId("srcid").build();
final Notification notification = new StreamlineEventAdapter(event);
new MockUp<NotificationQueueHandler>() {
@Mock
public void enqueue(Notifier notifier, Notification notification1) {
notifier.notify(notification);
}
};
new Expectations() {
{
mockProxyUtil.loadClassFromJar(anyString, "TestClass");
result = notifier;
tuple.getValueByField(anyString);
result = event;
}
};
Map<String, String> stormConf = new HashMap<>();
stormConf.put("catalog.root.url", "http://localhost:8080/api/v1/catalog");
stormConf.put("local.notifier.jar.path", "/tmp");
bolt.prepare(stormConf, null, collector);
bolt.execute(tuple);
new Verifications() {
{
hBaseNotificationStore.store(notification);
times = 1;
hBaseNotificationStore.updateNotificationStatus(notification.getId(), Notification.Status.DELIVERED);
times = 1;
collector.ack(tuple);
times = 1;
collector.fail(tuple);
times = 0;
}
};
}
use of com.hortonworks.streamline.streams.notification.Notification in project streamline by hortonworks.
the class NotificationBoltTest method setUp.
@Before
public void setUp() throws Exception {
bolt = new NotificationBolt(new NotificationSink() {
@Override
public String getNotifierName() {
return NOTIFIER_NAME;
}
@Override
public String getNotifierJarFileName() {
return NOTIFIER_NAME + ".jar";
}
@Override
public String getNotifierClassName() {
return "TestClass";
}
@Override
public Map<String, Object> getNotifierProperties() {
return new HashMap<>();
}
@Override
public Map<String, Object> getNotifierFieldValues() {
return new HashMap<>();
}
});
bolt.withNotificationStoreClass("com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore");
notifier = new Notifier() {
private NotificationContext myCtx;
@Override
public void open(NotificationContext ctx) {
System.out.println("Notifier open called with ctx " + ctx);
Assert.assertEquals(ctx.getConfig().getProperties(), NOTIFIER_PROPS);
Assert.assertEquals(ctx.getConfig().getDefaultFieldValues(), NOTIFIER_KV);
myCtx = ctx;
}
@Override
public void notify(Notification notification) {
System.out.println("Notifier notify called with notification " + notification);
String temp = (String) notification.getFieldsAndValues().get("temperature");
if (temp == null) {
myCtx.fail(notification.getId());
} else {
myCtx.ack(notification.getId());
}
}
@Override
public void close() {
System.out.println("Notifier Close called");
}
@Override
public boolean isPull() {
return false;
}
@Override
public List<String> getFields() {
return new ArrayList<>();
}
@Override
public NotificationContext getContext() {
return myCtx;
}
};
}
Aggregations