/** * This tests writing a message, reading its data, and removing it. * * @throws HBaseException */ @Test public void writeMessageData() throws HBaseException { MessagePersister mp = new MessagePersister(); mp.writeMessage(messageKey1, data1); byte[] result = mp.readMessage(messageKey1); assertTrue(Arrays.equals(result, data1)); mp.removeMessage(messageKey1); result = mp.readMessage(messageKey1); assertNull(result); }
/** * This tests writing a message and corresponding index metadata, then reading that index * metadata, then deleting the message and index metadata. * * @throws HBaseException */ @Test public void writeMessageAndIndex() throws HBaseException { MessagePersister mp = new MessagePersister(); mp.writeMessage(messageKey1, data1); mp.writeMessageIndex(messageKey1, metadataFields1); Map<String, byte[]> indexFields = mp.readMessageIndex(messageKey1); for (Entry<String, byte[]> field : indexFields.entrySet()) { assertTrue( Arrays.equals( metadataFields1.get(field.getKey()).toString().getBytes(), field.getValue())); } mp.removeMessageIndex(messageKey1); indexFields = mp.readMessageIndex(messageKey1); assertNotNull(indexFields); assertTrue(indexFields.size() == 0); mp.removeMessage(messageKey1); byte[] result = mp.readMessage(messageKey1); assertNull(result); }
/** * This tests writing a message along with some corresponding metadata, which is stored in a * separate column family for this row. * * @throws HBaseException */ @Test public void writeMessageWithMetaData() throws HBaseException { MessagePersister mp = new MessagePersister(); mp.writeMessage(messageKey1, dataAndMetadata1); Map<String, Map<String, byte[]>> resultMap = mp.readMessage(messageKey1, columnFamilies1); assertNotNull(resultMap); assertTrue(resultMap.size() == 2); for (String columnFamily : columnFamilies1) { Map<String, byte[]> columnFamilyDataMap = resultMap.get(columnFamily); assertTrue( columnFamily + " does not match.", Arrays.equals( dataAndMetadata1.get(columnFamily).get(MessagePersister.QUANTIFIER_VALUE), columnFamilyDataMap.get(MessagePersister.QUANTIFIER_VALUE))); } mp.removeMessage(messageKey1); resultMap = mp.readMessage(messageKey1, columnFamilies1); assertNotNull(resultMap); assertTrue(resultMap.size() == 0); }
/** * This tests writing messages, scanning the table, and removing the messages. * * @throws HBaseException */ @Test public void writeAndScanMessageData() throws HBaseException { MessagePersister mp = new MessagePersister(); HBaseFacade hbs = new HBaseFacade(); mp.writeMessage(messageKey1, data1); mp.writeMessage(messageKey2, data2); mp.writeMessage(messageKey3, data2); mp.writeMessage(messageKey4, data2); mp.writeMessage(messageKey5, data2); mp.writeMessage(messageKey6, data2); mp.writeMessage(messageKey7, data2); mp.writeMessage(messageKey8, data2); mp.writeMessage(messageKey9, data2); mp.writeMessage(messageKey10, data2); Map<String, byte[]> dataMap = hbs.scan( MessagePersister.TABLE_MESSAGE, 10, MessagePersister.COL_FAMILY_DATA, MessagePersister.QUANTIFIER_VALUE); assertTrue(Arrays.equals(dataMap.get(messageKey1), data1)); assertTrue(Arrays.equals(dataMap.get(messageKey2), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey3), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey4), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey5), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey6), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey7), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey8), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey9), data2)); assertTrue(Arrays.equals(dataMap.get(messageKey10), data2)); mp.removeMessage(messageKey1); mp.removeMessage(messageKey2); mp.removeMessage(messageKey3); mp.removeMessage(messageKey4); mp.removeMessage(messageKey5); mp.removeMessage(messageKey6); mp.removeMessage(messageKey7); mp.removeMessage(messageKey8); mp.removeMessage(messageKey9); mp.removeMessage(messageKey10); }
/** * This tests writing messages, scanning the table for the keys, and removing the messages. * * @throws HBaseException */ @Test public void writeAndScanMessageKeys() throws HBaseException { MessagePersister mp = new MessagePersister(); HBaseFacade hbs = new HBaseFacade(); mp.writeMessage(messageKey1, data1); mp.writeMessage(messageKey2, data2); mp.writeMessage(messageKey3, data2); mp.writeMessage(messageKey4, data2); mp.writeMessage(messageKey5, data2); mp.writeMessage(messageKey6, data2); mp.writeMessage(messageKey7, data2); mp.writeMessage(messageKey8, data2); mp.writeMessage(messageKey9, data2); mp.writeMessage(messageKey10, data2); Set<Object> keys = hbs.scanForKeys(MessagePersister.TABLE_MESSAGE); assertTrue("Did not return a key", keys.contains(messageKey1)); assertTrue("Did not return a key", keys.contains(messageKey2)); assertTrue("Did not return a key", keys.contains(messageKey3)); assertTrue("Did not return a key", keys.contains(messageKey4)); assertTrue("Did not return a key", keys.contains(messageKey5)); assertTrue("Did not return a key", keys.contains(messageKey6)); assertTrue("Did not return a key", keys.contains(messageKey7)); assertTrue("Did not return a key", keys.contains(messageKey8)); assertTrue("Did not return a key", keys.contains(messageKey9)); assertTrue("Did not return a key", keys.contains(messageKey10)); mp.removeMessage(messageKey1); mp.removeMessage(messageKey2); mp.removeMessage(messageKey3); mp.removeMessage(messageKey4); mp.removeMessage(messageKey5); mp.removeMessage(messageKey6); mp.removeMessage(messageKey7); mp.removeMessage(messageKey8); mp.removeMessage(messageKey9); mp.removeMessage(messageKey10); }