@Test(expected = RepositoryException.class) public void checkMostRecentRollupTest() { Experiment.ID experimentId = Experiment.ID.newInstance(); Experiment experiment = mock(Experiment.class); when(experiment.getID()).thenReturn(experimentId); List queryResult = mock(List.class); Parameters parameters = mock(Parameters.class, RETURNS_DEEP_STUBS); when(parameters.getContext().getContext()).thenReturn("TEST"); Date to = mock(Date.class); when(to.getTime()).thenReturn(9999L); when(transaction.select(anyString(), eq(experimentId), eq("TEST"))).thenReturn(queryResult); when(queryResult.isEmpty()).thenReturn(true); boolean result = databaseAnalytics.checkMostRecentRollup(experiment, parameters, to); assertThat(result, is(true)); when(queryResult.isEmpty()).thenReturn(false); Map map = mock(Map.class); Date maxDay = mock(Date.class); when(queryResult.get(0)).thenReturn(map); when(map.get("day")).thenReturn(maxDay); when(maxDay.getTime()).thenReturn(100000L); result = databaseAnalytics.checkMostRecentRollup(experiment, parameters, to); assertThat(result, is(true)); when(maxDay.getTime()).thenReturn(1000L); result = databaseAnalytics.checkMostRecentRollup(experiment, parameters, to); assertThat(result, is(false)); doThrow(new RuntimeException()).when(transaction) .select(anyString(), eq(experimentId), eq("TEST")); databaseAnalytics.checkMostRecentRollup(experiment, parameters, to); fail(); }
@Override public boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to) throws RepositoryException { try { Timestamp toTime = new Timestamp(to.getTime()); final String SQL_SELECT_ID = "SELECT day FROM experiment_rollup " + "WHERE experiment_id=? AND context=? ORDER BY day"; List result = transaction.select(SQL_SELECT_ID, experiment.getID(), parameters.getContext().getContext()); if (result.isEmpty()) { return true; } else { Map row = (Map) result.get(0); Date maxDay = (Date) row.get("day"); Timestamp maxStamp = new Timestamp(maxDay.getTime()); return maxStamp.after(toTime); } } catch (Exception e) { throw new RepositoryException("error reading counts from MySQL rollups", e); } }
DatabaseAnalytics implements AnalyticsRepository { @Override public boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to) throws RepositoryException { try { Timestamp toTime = new Timestamp(to.getTime()); final String SQL_SELECT_ID = "SELECT day FROM experiment_rollup " + "WHERE experiment_id=? AND context=? ORDER BY day"; List result = transaction.select(SQL_SELECT_ID, experiment.getID(), parameters.getContext().getContext()); if (result.isEmpty()) { return true; } else { Map row = (Map) result.get(0); Date maxDay = (Date) row.get("day"); Timestamp maxStamp = new Timestamp(maxDay.getTime()); return maxStamp.after(toTime); } } catch (Exception e) { throw new RepositoryException("error reading counts from MySQL rollups", e); } } }
DatabaseAnalytics implements AnalyticsRepository { @Override public boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to) throws RepositoryException { try { Timestamp toTime = new Timestamp(to.getTime()); final String SQL_SELECT_ID = "SELECT day FROM experiment_rollup " + "WHERE experiment_id=? AND context=? ORDER BY day"; List result = transaction.select(SQL_SELECT_ID, experiment.getID(), parameters.getContext().getContext()); if (result.isEmpty()) { return true; } else { Map row = (Map) result.get(0); Date maxDay = (Date) row.get("day"); Timestamp maxStamp = new Timestamp(maxDay.getTime()); return maxStamp.after(toTime); } } catch (Exception e) { throw new RepositoryException("error reading counts from MySQL rollups", e); } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); }
DatabaseAnalytics implements AnalyticsRepository { @Override public boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to) throws RepositoryException { try { Timestamp toTime = new Timestamp(to.getTime()); final String SQL_SELECT_ID = "SELECT day FROM experiment_rollup " + "WHERE experiment_id=? AND context=? ORDER BY day"; List result = transaction.select(SQL_SELECT_ID, experiment.getID(), parameters.getContext().getContext()); if (result.isEmpty()) { return true; } else { Map row = (Map) result.get(0); Date maxDay = (Date) row.get("day"); Timestamp maxStamp = new Timestamp(maxDay.getTime()); return maxStamp.after(toTime); } } catch (Exception e) { throw new RepositoryException("error reading counts from MySQL rollups", e); } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); @Override List<Map> getRollupRows(Experiment.ID experimentId, String rollupDate, Parameters parameters); @Override List<Map> getActionsRows(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getImpressionRows(Experiment.ID experimentID, Parameters parameters); @Override Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID); @Override List<Map> getCountsFromRollups(Experiment.ID experimentID, Parameters parameters); @Override boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to); }
DatabaseAnalytics implements AnalyticsRepository { @Override public boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to) throws RepositoryException { try { Timestamp toTime = new Timestamp(to.getTime()); final String SQL_SELECT_ID = "SELECT day FROM experiment_rollup " + "WHERE experiment_id=? AND context=? ORDER BY day"; List result = transaction.select(SQL_SELECT_ID, experiment.getID(), parameters.getContext().getContext()); if (result.isEmpty()) { return true; } else { Map row = (Map) result.get(0); Date maxDay = (Date) row.get("day"); Timestamp maxStamp = new Timestamp(maxDay.getTime()); return maxStamp.after(toTime); } } catch (Exception e) { throw new RepositoryException("error reading counts from MySQL rollups", e); } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); @Override List<Map> getRollupRows(Experiment.ID experimentId, String rollupDate, Parameters parameters); @Override List<Map> getActionsRows(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters); @Override List<Map> getImpressionRows(Experiment.ID experimentID, Parameters parameters); @Override Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID); @Override List<Map> getCountsFromRollups(Experiment.ID experimentID, Parameters parameters); @Override boolean checkMostRecentRollup(Experiment experiment, Parameters parameters, Date to);  }