List of usage examples for java.util NavigableMap firstEntry
Map.Entry<K, V> firstEntry();
From source file:NavigableMapSample.java
public static void main(String args[]) { Calendar now = Calendar.getInstance(); Locale locale = Locale.getDefault(); Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale); NavigableMap<String, Integer> nav = new TreeMap<String, Integer>(names); System.out.printf("Whole list:%n%s%n", nav); System.out.printf("First key: %s\tFirst entry: %s%n", nav.firstKey(), nav.firstEntry()); }
From source file:Main.java
public static void main(String[] args) { NavigableMap<String, Integer> navigableMap = new TreeMap<String, Integer>(); String[] letters = { "a", "b", "c" }; int[] ints = { 3, 2, 1 }; for (int i = 0; i < letters.length; i++) { navigableMap.put(letters[i], ints[i]); }/*from w ww.j a v a2 s .c o m*/ System.out.println("Map = " + navigableMap); System.out.println("First entry = " + navigableMap.firstEntry()); }
From source file:velocitekProStartAnalyzer.MainWindow.java
private void createChartPanel() { XYSeriesCollection dataset = JDBCPointDao.dataSet; JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart, true, false, false, true, false); chartPanel.setMinimumDrawWidth(0);/*from w w w . ja v a2 s . com*/ chartPanel.setMinimumDrawHeight(0); chartPanel.setMaximumDrawWidth(1920); chartPanel.setMaximumDrawHeight(1200); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(btnAvgSpeedChart); chartPanel.getPopupMenu().add(btnMedianSpeedChart); chartPanel.getPopupMenu().add(btnResetSpeedChart); chartPanel.getPopupMenu().addSeparator(); btnMenuSaveSubmenuForChart = new JMenu("Save"); chartPanel.getPopupMenu().add(btnMenuSaveSubmenuForChart); if (JDBCPointDao.points.isEmpty()) { btnSaveAsVCC.setEnabled(false); } saveChartAsPng(chartPanel); btnMenuSaveSubmenuForChart.add(btnSaveChartAsPngForChart); btnMenuSaveSubmenuForChart.add(btnSaveTableAsPngForChart); btnMenuSaveSubmenuForChart.add(btnSaveMapAsPngForChart); btnMenuSaveSubmenuForChart.addSeparator(); btnMenuSaveSubmenuForChart.add(btnSaveAsVCC); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } x = Math.round(x); if (SwingUtilities.isLeftMouseButton(event.getTrigger()) && event.getTrigger().isShiftDown()) { for (PointDto cord : JDBCPointDao.points) { { if (cord.getPointID() == x) { if (pointTable.getSelectionModel() == null) { for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.setRowSelectionInterval(i, i); } } } else { for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.addRowSelectionInterval(pointTable.getSelectedRow(), i); } } } pointTable.scrollRectToVisible( pointTable.getCellRect(pointTable.getSelectedRow(), 0, true)); } } } } else { for (PointDto cord : JDBCPointDao.points) { { if (cord.getPointID() == x) { if (pointTable.getSelectionModel() != null) { pointTable.getSelectionModel().clearSelection(); } for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.setRowSelectionInterval(i, i); } } pointTable.scrollRectToVisible( pointTable.getCellRect(pointTable.getSelectedRow(), 0, true)); //MainWindow.pointTable.revalidate(); } } } } } @Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x); xCrosshair.setValue(x); yCrosshair.setValue(y); x = Math.round(x); for (PointDto cord : JDBCPointDao.points) { if (cord.getPointID() == x) { mapPanel.map().removeMapMarker(mapPanel.getMapPoint()); mapPanel.setMapPoint( new MapMarkerDot(null, null, cord.getPointLatidude(), cord.getPointLongtidude())); mapPanel.setMapPoint(mapPanel.getMapPoint()); mapPanel.getMapPoint().setColor(colorMapMarkerCircle); mapPanel.getMapPoint().setBackColor(colorMapMarkerHover); mapPanel.map().addMapMarker(mapPanel.getMapPoint()); } } } }); XYPlot xyPlot = (XYPlot) chart.getPlot(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); NavigableMap<Double, PointDto> pointDtoSortedSpeedMap = new TreeMap<Double, PointDto>(); if (!JDBCPointDao.points.isEmpty()) { for (PointDto pointDto : JDBCPointDao.points) { pointDtoSortedSpeedMap.put(pointDto.getPointSpeed(), pointDto); } rangeAxis.setRange(pointDtoSortedSpeedMap.firstEntry().getKey() - 0.1, pointDtoSortedSpeedMap.lastEntry().getKey() + 0.1); } CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); chartPanel.addOverlay(crosshairOverlay); graphPanel.removeAll(); graphPanel.add(chartPanel, BorderLayout.CENTER); graphPanel.revalidate(); graphPanel.repaint(); graphMapSplitPanel.revalidate(); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testFirstEntry() { K[] keys = getSortedKeys();//from ww w .j a v a 2s . c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); // test with a single entry map map.put(keys[0], values[0]); assertEquals(keys[0], map.firstEntry().getKey()); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.firstEntry().getKey()); assertEquals(keys[0], map.lastEntry().getKey()); assertEquals(map.lastEntry().getKey(), map.firstEntry().getKey()); // test with two entry map map.put(keys[1], values[1]); Entry<K, V> entry = map.firstEntry(); verifyEntry(entry); assertEquals(keys[0], entry.getKey()); assertFalse(keys[1].equals(map.firstEntry().getKey())); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.firstEntry().getKey()); assertFalse(keys[0].equals(map.lastEntry().getKey())); assertFalse(map.lastEntry().getKey().equals(map.firstEntry().getKey())); map.clear(); assertNull(map.firstEntry()); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
/** * Test method for 'java.util.SortedMap.headMap(Object)' and * 'java.util.NavigableMap.headMap(Object, boolean)'. * * @see java.util.SortedMap#headMap(Object) * @see java.util.NavigableMap#headMap(Object, boolean) */// ww w. j av a 2 s . com public void testHeadMap_entries_size() { // test with no entries K[] keys = getSortedKeys(); assertEquals(0, createNavigableMap().headMap(keys[0]).size()); NavigableMap<K, V> exclusiveHeadMap = createNavigableMap().headMap(keys[0], false); assertEquals(0, exclusiveHeadMap.size()); assertNull(exclusiveHeadMap.firstEntry()); assertNull(exclusiveHeadMap.lastEntry()); try { assertNull(exclusiveHeadMap.firstKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } try { assertNull(exclusiveHeadMap.lastKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } NavigableMap<K, V> inclusiveHeadMap = createNavigableMap().headMap(keys[0], true); assertEquals(0, inclusiveHeadMap.size()); assertNull(inclusiveHeadMap.firstEntry()); assertNull(inclusiveHeadMap.lastEntry()); try { assertNull(inclusiveHeadMap.firstKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } try { assertNull(inclusiveHeadMap.lastKey()); fail(); } catch (NoSuchElementException e) { // expected outcome } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testLastEntry() { K[] keys = getSortedKeys();/* w w w . j ava2s.com*/ V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); // test with a single entry map map.put(keys[0], values[0]); assertEquals(keys[0], map.lastEntry().getKey()); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.lastEntry().getKey()); assertEquals(keys[0], map.firstEntry().getKey()); assertEquals(values[0], map.firstEntry().getValue()); assertEquals(map.firstEntry().getKey(), map.lastEntry().getKey()); // test with two entry map map.put(keys[1], values[1]); assertEquals(keys[1], map.lastEntry().getKey()); assertFalse(keys[0].equals(map.lastEntry().getKey())); // is it consistent with other methods assertEquals(map.keySet().toArray()[1], map.lastEntry().getKey()); Entry<K, V> entry = map.firstEntry(); verifyEntry(entry); assertEquals(keys[0], entry.getKey()); assertFalse(map.firstEntry().getKey().equals(map.lastEntry().getKey())); map.clear(); assertNull(map.lastEntry()); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.java
/** * Get the entry position that come before the specified position in the message stream, using information from the * ledger list and each ledger entries count. * * @param position/*from w w w .j a v a 2 s. c o m*/ * the current position * @return the previous position */ PositionImpl getPreviousPosition(PositionImpl position) { if (position.getEntryId() > 0) { return PositionImpl.get(position.getLedgerId(), position.getEntryId() - 1); } // The previous position will be the last position of an earlier ledgers NavigableMap<Long, LedgerInfo> headMap = ledgers.headMap(position.getLedgerId(), false); if (headMap.isEmpty()) { // There is no previous ledger, return an invalid position in the current ledger return PositionImpl.get(position.getLedgerId(), -1); } // We need to find the most recent non-empty ledger for (long ledgerId : headMap.descendingKeySet()) { LedgerInfo li = headMap.get(ledgerId); if (li.getEntries() > 0) { return PositionImpl.get(li.getLedgerId(), li.getEntries() - 1); } } // in case there are only empty ledgers, we return a position in the first one return PositionImpl.get(headMap.firstEntry().getKey(), -1); }
From source file:org.apache.hadoop.hbase.catalog.TestMetaReaderEditorNoCluster.java
/** * Test that MetaReader will ride over server throwing * "Server not running" IOEs.// ww w . ja v a2 s.com * @see @link {https://issues.apache.org/jira/browse/HBASE-3446} * @throws IOException * @throws InterruptedException */ @Test public void testRideOverServerNotRunning() throws IOException, InterruptedException, ServiceException { // Need a zk watcher. ZooKeeperWatcher zkw = new ZooKeeperWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), ABORTABLE, true); // This is a servername we use in a few places below. ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis()); HConnection connection; CatalogTracker ct = null; try { // Mock an ClientProtocol. Our mock implementation will fail a few // times when we go to open a scanner. final ClientProtos.ClientService.BlockingInterface implementation = Mockito .mock(ClientProtos.ClientService.BlockingInterface.class); // When scan called throw IOE 'Server not running' a few times // before we return a scanner id. Whats WEIRD is that these // exceptions do not show in the log because they are caught and only // printed if we FAIL. We eventually succeed after retry so these don't // show. We will know if they happened or not because we will ask // mockito at the end of this test to verify that scan was indeed // called the wanted number of times. List<Cell> kvs = new ArrayList<Cell>(); final byte[] rowToVerify = Bytes.toBytes("rowToVerify"); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, HRegionInfo.FIRST_META_REGIONINFO.toByteArray())); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, Bytes.toBytes(sn.getHostAndPort()))); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER, Bytes.toBytes(sn.getStartcode()))); final List<CellScannable> cellScannables = new ArrayList<CellScannable>(1); cellScannables.add(Result.create(kvs)); final ScanResponse.Builder builder = ScanResponse.newBuilder(); for (CellScannable result : cellScannables) { builder.addCellsPerResult(((Result) result).size()); } Mockito.when(implementation.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())) .thenThrow(new ServiceException("Server not running (1 of 3)")) .thenThrow(new ServiceException("Server not running (2 of 3)")) .thenThrow(new ServiceException("Server not running (3 of 3)")) .thenReturn(ScanResponse.newBuilder().setScannerId(1234567890L).build()) .thenAnswer(new Answer<ScanResponse>() { public ScanResponse answer(InvocationOnMock invocation) throws Throwable { ((PayloadCarryingRpcController) invocation.getArguments()[0]) .setCellScanner(CellUtil.createCellScanner(cellScannables)); return builder.build(); } }).thenReturn(ScanResponse.newBuilder().setMoreResults(false).build()); // Associate a spied-upon HConnection with UTIL.getConfiguration. Need // to shove this in here first so it gets picked up all over; e.g. by // HTable. connection = HConnectionTestingUtility.getSpiedConnection(UTIL.getConfiguration()); // Fix the location lookup so it 'works' though no network. First // make an 'any location' object. final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, sn); // Return the any location object when locateRegion is called in HTable // constructor and when its called by ServerCallable (it uses getRegionLocation). // The ugly format below comes of 'Important gotcha on spying real objects!' from // http://mockito.googlecode.com/svn/branches/1.6/javadoc/org/mockito/Mockito.html Mockito.doReturn(anyLocation).when(connection).locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any()); Mockito.doReturn(anyLocation).when(connection).getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean()); // Now shove our HRI implementation into the spied-upon connection. Mockito.doReturn(implementation).when(connection).getClient(Mockito.any(ServerName.class)); // Now start up the catalogtracker with our doctored Connection. ct = new CatalogTracker(zkw, null, connection, ABORTABLE); ct.start(); // Scan meta for user tables and verify we got back expected answer. NavigableMap<HRegionInfo, Result> hris = MetaReader.getServerUserRegions(ct, sn); assertEquals(1, hris.size()); assertTrue(hris.firstEntry().getKey().equals(HRegionInfo.FIRST_META_REGIONINFO)); assertTrue(Bytes.equals(rowToVerify, hris.firstEntry().getValue().getRow())); // Finally verify that scan was called four times -- three times // with exception and then on 4th, 5th and 6th attempt we succeed Mockito.verify(implementation, Mockito.times(6)).scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any()); } finally { if (ct != null) ct.stop(); HConnectionManager.deleteConnection(UTIL.getConfiguration()); zkw.close(); } }
From source file:org.apache.hadoop.hbase.TestMetaTableAccessorNoCluster.java
/** * Test that MetaTableAccessor will ride over server throwing * "Server not running" IOEs.//from ww w . java2s .co m * @see @link {https://issues.apache.org/jira/browse/HBASE-3446} * @throws IOException * @throws InterruptedException */ @Test public void testRideOverServerNotRunning() throws IOException, InterruptedException, ServiceException { // Need a zk watcher. ZooKeeperWatcher zkw = new ZooKeeperWatcher(UTIL.getConfiguration(), this.getClass().getSimpleName(), ABORTABLE, true); // This is a servername we use in a few places below. ServerName sn = ServerName.valueOf("example.com", 1234, System.currentTimeMillis()); ClusterConnection connection = null; try { // Mock an ClientProtocol. Our mock implementation will fail a few // times when we go to open a scanner. final ClientProtos.ClientService.BlockingInterface implementation = Mockito .mock(ClientProtos.ClientService.BlockingInterface.class); // When scan called throw IOE 'Server not running' a few times // before we return a scanner id. Whats WEIRD is that these // exceptions do not show in the log because they are caught and only // printed if we FAIL. We eventually succeed after retry so these don't // show. We will know if they happened or not because we will ask // mockito at the end of this test to verify that scan was indeed // called the wanted number of times. List<Cell> kvs = new ArrayList<Cell>(); final byte[] rowToVerify = Bytes.toBytes("rowToVerify"); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, HRegionInfo.FIRST_META_REGIONINFO.toByteArray())); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER, Bytes.toBytes(sn.getHostAndPort()))); kvs.add(new KeyValue(rowToVerify, HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER, Bytes.toBytes(sn.getStartcode()))); final List<CellScannable> cellScannables = new ArrayList<CellScannable>(1); cellScannables.add(Result.create(kvs)); final ScanResponse.Builder builder = ScanResponse.newBuilder(); for (CellScannable result : cellScannables) { builder.addCellsPerResult(((Result) result).size()); } Mockito.when(implementation.scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any())) .thenThrow(new ServiceException("Server not running (1 of 3)")) .thenThrow(new ServiceException("Server not running (2 of 3)")) .thenThrow(new ServiceException("Server not running (3 of 3)")) .thenReturn(ScanResponse.newBuilder().setScannerId(1234567890L).build()) .thenAnswer(new Answer<ScanResponse>() { public ScanResponse answer(InvocationOnMock invocation) throws Throwable { ((PayloadCarryingRpcController) invocation.getArguments()[0]) .setCellScanner(CellUtil.createCellScanner(cellScannables)); return builder.build(); } }).thenReturn(ScanResponse.newBuilder().setMoreResults(false).build()); // Associate a spied-upon HConnection with UTIL.getConfiguration. Need // to shove this in here first so it gets picked up all over; e.g. by // HTable. connection = HConnectionTestingUtility.getSpiedConnection(UTIL.getConfiguration()); // Fix the location lookup so it 'works' though no network. First // make an 'any location' object. final HRegionLocation anyLocation = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, sn); final RegionLocations rl = new RegionLocations(anyLocation); // Return the RegionLocations object when locateRegion // The ugly format below comes of 'Important gotcha on spying real objects!' from // http://mockito.googlecode.com/svn/branches/1.6/javadoc/org/mockito/Mockito.html Mockito.doReturn(rl).when(connection).locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.anyInt()); // Now shove our HRI implementation into the spied-upon connection. Mockito.doReturn(implementation).when(connection).getClient(Mockito.any(ServerName.class)); // Scan meta for user tables and verify we got back expected answer. NavigableMap<HRegionInfo, Result> hris = MetaTableAccessor.getServerUserRegions(connection, sn); assertEquals(1, hris.size()); assertTrue(hris.firstEntry().getKey().equals(HRegionInfo.FIRST_META_REGIONINFO)); assertTrue(Bytes.equals(rowToVerify, hris.firstEntry().getValue().getRow())); // Finally verify that scan was called four times -- three times // with exception and then on 4th, 5th and 6th attempt we succeed Mockito.verify(implementation, Mockito.times(6)).scan((RpcController) Mockito.any(), (ScanRequest) Mockito.any()); } finally { if (connection != null && !connection.isClosed()) connection.close(); zkw.close(); } }
From source file:org.apache.metron.indexing.dao.UpdateIntegrationTest.java
@Test public void test() throws Exception { List<Map<String, Object>> inputData = new ArrayList<>(); for (int i = 0; i < 10; ++i) { final String name = "message" + i; inputData.add(new HashMap<String, Object>() { {// w w w .ja v a 2 s . co m put("source.type", SENSOR_NAME); put("name", name); put("timestamp", System.currentTimeMillis()); put(Constants.GUID, name); } }); } addTestData(getIndexName(), SENSOR_NAME, inputData); List<Map<String, Object>> docs = null; for (int t = 0; t < MAX_RETRIES; ++t, Thread.sleep(SLEEP_MS)) { docs = getIndexedTestData(getIndexName(), SENSOR_NAME); if (docs.size() >= 10) { break; } } Assert.assertEquals(10, docs.size()); //modify the first message and add a new field { Map<String, Object> message0 = new HashMap<String, Object>(inputData.get(0)) { { put("new-field", "metron"); } }; String guid = "" + message0.get(Constants.GUID); getDao().replace(new ReplaceRequest() { { setReplacement(message0); setGuid(guid); setSensorType(SENSOR_NAME); setIndex(getIndexName()); } }, Optional.empty()); Assert.assertEquals(1, getMockHTable().size()); findUpdatedDoc(message0, guid, SENSOR_NAME); { //ensure hbase is up to date Get g = new Get(HBaseDao.Key.toBytes(new HBaseDao.Key(guid, SENSOR_NAME))); Result r = getMockHTable().get(g); NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes()); Assert.assertEquals(1, columns.size()); Assert.assertEquals(message0, JSONUtils.INSTANCE.load(new String(columns.lastEntry().getValue()), JSONUtils.MAP_SUPPLIER)); } { //ensure ES is up-to-date long cnt = 0; for (int t = 0; t < MAX_RETRIES && cnt == 0; ++t, Thread.sleep(SLEEP_MS)) { docs = getIndexedTestData(getIndexName(), SENSOR_NAME); cnt = docs.stream().filter(d -> message0.get("new-field").equals(d.get("new-field"))).count(); } Assert.assertNotEquals("Data store is not updated!", cnt, 0); } } //modify the same message and modify the new field { Map<String, Object> message0 = new HashMap<String, Object>(inputData.get(0)) { { put("new-field", "metron2"); } }; String guid = "" + message0.get(Constants.GUID); getDao().replace(new ReplaceRequest() { { setReplacement(message0); setGuid(guid); setSensorType(SENSOR_NAME); setIndex(getIndexName()); } }, Optional.empty()); Assert.assertEquals(1, getMockHTable().size()); Document doc = getDao().getLatest(guid, SENSOR_NAME); Assert.assertEquals(message0, doc.getDocument()); findUpdatedDoc(message0, guid, SENSOR_NAME); { //ensure hbase is up to date Get g = new Get(HBaseDao.Key.toBytes(new HBaseDao.Key(guid, SENSOR_NAME))); Result r = getMockHTable().get(g); NavigableMap<byte[], byte[]> columns = r.getFamilyMap(CF.getBytes()); Assert.assertEquals(2, columns.size()); Assert.assertEquals(message0, JSONUtils.INSTANCE.load(new String(columns.lastEntry().getValue()), JSONUtils.MAP_SUPPLIER)); Assert.assertNotEquals(message0, JSONUtils.INSTANCE .load(new String(columns.firstEntry().getValue()), JSONUtils.MAP_SUPPLIER)); } { //ensure ES is up-to-date long cnt = 0; for (int t = 0; t < MAX_RETRIES && cnt == 0; ++t, Thread.sleep(SLEEP_MS)) { docs = getIndexedTestData(getIndexName(), SENSOR_NAME); cnt = docs.stream().filter(d -> message0.get("new-field").equals(d.get("new-field"))).count(); } Assert.assertNotEquals("Data store is not updated!", cnt, 0); } } }