@Test public void testCache() { FluoQueryMetadataDAO mockDAO = Mockito.mock(FluoQueryMetadataDAO.class); Transaction mockTx = Mockito.mock(Transaction.class); String nodeId = NodeType.generateNewFluoIdForType(NodeType.STATEMENT_PATTERN); StatementPatternMetadata metadata = StatementPatternMetadata.builder(nodeId).setParentNodeId("parent") .setStatementPattern("pattern").setVarOrder(new VariableOrder("xyz")).build(); when(mockDAO.readStatementPatternMetadata(mockTx, nodeId)).thenReturn(metadata); FluoQueryMetadataCache cache = new FluoQueryMetadataCache(mockDAO, 20, 2); assertEquals(metadata, cache.readStatementPatternMetadata(mockTx, nodeId)); cache.readStatementPatternMetadata(mockTx, nodeId); cache.readStatementPatternMetadata(mockTx, nodeId); cache.readStatementPatternMetadata(mockTx, nodeId); cache.readStatementPatternMetadata(mockTx, nodeId); Mockito.verify(mockDAO, Mockito.times(1)).readStatementPatternMetadata(mockTx, nodeId); }
@Override public StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId) { checkNotNull(nodeId); checkNotNull(tx); Optional<NodeType> type = NodeType.fromNodeId(nodeId); checkArgument(type.isPresent() && type.get() == NodeType.STATEMENT_PATTERN); try { LOG.debug("Retrieving Metadata from Cache: {}", nodeId); return (StatementPatternMetadata) commonNodeMetadataCache.get(nodeId, () -> { LOG.debug("Seeking Metadata from Fluo Table: {}", nodeId); return dao.readStatementPatternMetadata(tx, nodeId); }); } catch (Exception e) { throw new RuntimeException("Unable to access StatementPatternMetadata for nodeId: " + nodeId, e); } }
FluoQueryMetadataCache extends FluoQueryMetadataDAO { @Override public StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId) { checkNotNull(nodeId); checkNotNull(tx); Optional<NodeType> type = NodeType.fromNodeId(nodeId); checkArgument(type.isPresent() && type.get() == NodeType.STATEMENT_PATTERN); try { LOG.debug("Retrieving Metadata from Cache: {}", nodeId); return (StatementPatternMetadata) commonNodeMetadataCache.get(nodeId, () -> { LOG.debug("Seeking Metadata from Fluo Table: {}", nodeId); return dao.readStatementPatternMetadata(tx, nodeId); }); } catch (Exception e) { throw new RuntimeException("Unable to access StatementPatternMetadata for nodeId: " + nodeId, e); } } }
FluoQueryMetadataCache extends FluoQueryMetadataDAO { @Override public StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId) { checkNotNull(nodeId); checkNotNull(tx); Optional<NodeType> type = NodeType.fromNodeId(nodeId); checkArgument(type.isPresent() && type.get() == NodeType.STATEMENT_PATTERN); try { LOG.debug("Retrieving Metadata from Cache: {}", nodeId); return (StatementPatternMetadata) commonNodeMetadataCache.get(nodeId, () -> { LOG.debug("Seeking Metadata from Fluo Table: {}", nodeId); return dao.readStatementPatternMetadata(tx, nodeId); }); } catch (Exception e) { throw new RuntimeException("Unable to access StatementPatternMetadata for nodeId: " + nodeId, e); } } FluoQueryMetadataCache(FluoQueryMetadataDAO dao, int capacity, int concurrencyLevel); }
FluoQueryMetadataCache extends FluoQueryMetadataDAO { @Override public StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId) { checkNotNull(nodeId); checkNotNull(tx); Optional<NodeType> type = NodeType.fromNodeId(nodeId); checkArgument(type.isPresent() && type.get() == NodeType.STATEMENT_PATTERN); try { LOG.debug("Retrieving Metadata from Cache: {}", nodeId); return (StatementPatternMetadata) commonNodeMetadataCache.get(nodeId, () -> { LOG.debug("Seeking Metadata from Fluo Table: {}", nodeId); return dao.readStatementPatternMetadata(tx, nodeId); }); } catch (Exception e) { throw new RuntimeException("Unable to access StatementPatternMetadata for nodeId: " + nodeId, e); } } FluoQueryMetadataCache(FluoQueryMetadataDAO dao, int capacity, int concurrencyLevel); int getCapacity(); int getConcurrencyLevel(); @Override StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId); @Override JoinMetadata readJoinMetadata(SnapshotBase tx, String nodeId); @Override FilterMetadata readFilterMetadata(SnapshotBase tx, String nodeId); @Override ProjectionMetadata readProjectionMetadata(SnapshotBase tx, String nodeId); @Override AggregationMetadata readAggregationMetadata(SnapshotBase tx, String nodeId); @Override ConstructQueryMetadata readConstructQueryMetadata(SnapshotBase tx, String nodeId); @Override PeriodicQueryMetadata readPeriodicQueryMetadata(SnapshotBase tx, String nodeId); @Override QueryMetadata readQueryMetadata(SnapshotBase tx, String nodeId); Bytes readMetadadataEntry(SnapshotBase tx, String rowId, Column column); void clear(); }
FluoQueryMetadataCache extends FluoQueryMetadataDAO { @Override public StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId) { checkNotNull(nodeId); checkNotNull(tx); Optional<NodeType> type = NodeType.fromNodeId(nodeId); checkArgument(type.isPresent() && type.get() == NodeType.STATEMENT_PATTERN); try { LOG.debug("Retrieving Metadata from Cache: {}", nodeId); return (StatementPatternMetadata) commonNodeMetadataCache.get(nodeId, () -> { LOG.debug("Seeking Metadata from Fluo Table: {}", nodeId); return dao.readStatementPatternMetadata(tx, nodeId); }); } catch (Exception e) { throw new RuntimeException("Unable to access StatementPatternMetadata for nodeId: " + nodeId, e); } } FluoQueryMetadataCache(FluoQueryMetadataDAO dao, int capacity, int concurrencyLevel); int getCapacity(); int getConcurrencyLevel(); @Override StatementPatternMetadata readStatementPatternMetadata(SnapshotBase tx, String nodeId); @Override JoinMetadata readJoinMetadata(SnapshotBase tx, String nodeId); @Override FilterMetadata readFilterMetadata(SnapshotBase tx, String nodeId); @Override ProjectionMetadata readProjectionMetadata(SnapshotBase tx, String nodeId); @Override AggregationMetadata readAggregationMetadata(SnapshotBase tx, String nodeId); @Override ConstructQueryMetadata readConstructQueryMetadata(SnapshotBase tx, String nodeId); @Override PeriodicQueryMetadata readPeriodicQueryMetadata(SnapshotBase tx, String nodeId); @Override QueryMetadata readQueryMetadata(SnapshotBase tx, String nodeId); Bytes readMetadadataEntry(SnapshotBase tx, String rowId, Column column); void clear();  }