@Test(expected = RepositoryException.class) public void getJointActionsTest() { Experiment.ID experimentId = Experiment.ID.newInstance(); Parameters parameters = mock(Parameters.class, RETURNS_DEEP_STUBS); when(parameters.getContext().getContext()).thenReturn("TEST"); Date from = mock(Date.class), to = mock(Date.class); when(parameters.getFromTime()).thenReturn(from); when(parameters.getToTime()).thenReturn(to); List<String> actions = new ArrayList<String>(); actions.add("TEST_ACTION"); when(parameters.getActions()).thenReturn(actions); List<Map> expected = mock(List.class); when(transaction.select(anyString(), Matchers.anyVararg())).thenReturn(expected); List<Map> result = databaseAnalytics.getJointActions(experimentId, parameters); assertThat(result, is(expected)); doThrow(new RuntimeException()).when(transaction) .select(anyString(), Matchers.anyVararg()); databaseAnalytics.getJointActions(experimentId, parameters); fail(); }
@Override public List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { Date from_ts = parameters.getFromTime(); Date to_ts = parameters.getToTime(); String sqlBase = "bucket_label as bid, count(user_id) as c, count(distinct user_id) as cu"; StringBuilder sqlParams = new StringBuilder(" where experiment_id = ? and context = ?"); List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext()); if (from_ts != null) { params.add(from_ts); sqlParams.append(" and timestamp >= ?"); } if (to_ts != null) { params.add(to_ts); sqlParams.append(" and timestamp <= ?"); } addActionsToSql(parameters, sqlParams, params); Object[] bucketSqlData = new Object[params.size()]; params.toArray(bucketSqlData); String sqlJointActions = "select " + sqlBase + " from event_action" + sqlParams + " group by bucket_label"; List<Map> jointActionsRows = transaction.select(sqlJointActions, bucketSqlData); return jointActionsRows; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } }
DatabaseAnalytics implements AnalyticsRepository { @Override public List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { Date from_ts = parameters.getFromTime(); Date to_ts = parameters.getToTime(); String sqlBase = "bucket_label as bid, count(user_id) as c, count(distinct user_id) as cu"; StringBuilder sqlParams = new StringBuilder(" where experiment_id = ? and context = ?"); List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext()); if (from_ts != null) { params.add(from_ts); sqlParams.append(" and timestamp >= ?"); } if (to_ts != null) { params.add(to_ts); sqlParams.append(" and timestamp <= ?"); } addActionsToSql(parameters, sqlParams, params); Object[] bucketSqlData = new Object[params.size()]; params.toArray(bucketSqlData); String sqlJointActions = "select " + sqlBase + " from event_action" + sqlParams + " group by bucket_label"; List<Map> jointActionsRows = transaction.select(sqlJointActions, bucketSqlData); return jointActionsRows; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } } }
DatabaseAnalytics implements AnalyticsRepository { @Override public List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { Date from_ts = parameters.getFromTime(); Date to_ts = parameters.getToTime(); String sqlBase = "bucket_label as bid, count(user_id) as c, count(distinct user_id) as cu"; StringBuilder sqlParams = new StringBuilder(" where experiment_id = ? and context = ?"); List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext()); if (from_ts != null) { params.add(from_ts); sqlParams.append(" and timestamp >= ?"); } if (to_ts != null) { params.add(to_ts); sqlParams.append(" and timestamp <= ?"); } addActionsToSql(parameters, sqlParams, params); Object[] bucketSqlData = new Object[params.size()]; params.toArray(bucketSqlData); String sqlJointActions = "select " + sqlBase + " from event_action" + sqlParams + " group by bucket_label"; List<Map> jointActionsRows = transaction.select(sqlJointActions, bucketSqlData); return jointActionsRows; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); }
DatabaseAnalytics implements AnalyticsRepository { @Override public List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { Date from_ts = parameters.getFromTime(); Date to_ts = parameters.getToTime(); String sqlBase = "bucket_label as bid, count(user_id) as c, count(distinct user_id) as cu"; StringBuilder sqlParams = new StringBuilder(" where experiment_id = ? and context = ?"); List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext()); if (from_ts != null) { params.add(from_ts); sqlParams.append(" and timestamp >= ?"); } if (to_ts != null) { params.add(to_ts); sqlParams.append(" and timestamp <= ?"); } addActionsToSql(parameters, sqlParams, params); Object[] bucketSqlData = new Object[params.size()]; params.toArray(bucketSqlData); String sqlJointActions = "select " + sqlBase + " from event_action" + sqlParams + " group by bucket_label"; List<Map> jointActionsRows = transaction.select(sqlJointActions, bucketSqlData); return jointActionsRows; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", 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 List<Map> getJointActions(Experiment.ID experimentID, Parameters parameters) throws RepositoryException { try { Date from_ts = parameters.getFromTime(); Date to_ts = parameters.getToTime(); String sqlBase = "bucket_label as bid, count(user_id) as c, count(distinct user_id) as cu"; StringBuilder sqlParams = new StringBuilder(" where experiment_id = ? and context = ?"); List params = new ArrayList(); params.add(experimentID); params.add(parameters.getContext().getContext()); if (from_ts != null) { params.add(from_ts); sqlParams.append(" and timestamp >= ?"); } if (to_ts != null) { params.add(to_ts); sqlParams.append(" and timestamp <= ?"); } addActionsToSql(parameters, sqlParams, params); Object[] bucketSqlData = new Object[params.size()]; params.toArray(bucketSqlData); String sqlJointActions = "select " + sqlBase + " from event_action" + sqlParams + " group by bucket_label"; List<Map> jointActionsRows = transaction.select(sqlJointActions, bucketSqlData); return jointActionsRows; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", 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);  }