@Test(expected = RepositoryException.class) public void getEmptyBucketsTest() { Experiment.ID experimentId = Experiment.ID.newInstance(); List<Map> input = new ArrayList<Map>(); Map<String, String> map = new HashMap<String, String>(); map.put("label", "TEST_LABEL"); input.add(map); when(transaction.select(anyString(), Matchers.anyVararg())).thenReturn(input); Map<Bucket.Label, BucketCounts> result = databaseAnalytics.getEmptyBuckets(experimentId); assertThat(result.size(), is(1)); assertThat(result.get(Bucket.Label.valueOf("TEST_LABEL")).getLabel().toString(), is("TEST_LABEL")); assertThat(result.get(Bucket.Label.valueOf("TEST_LABEL")).getActionCounts().size(), is(0)); doThrow(new RuntimeException()).when(transaction) .select(anyString(), Matchers.anyVararg()); databaseAnalytics.getEmptyBuckets(experimentId); fail(); }
@Override public Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID) throws RepositoryException { try { List<Map> bucketRows = transaction.select("select label from bucket where experiment_id=?", experimentID); Counts impressions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Counts jointActions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Map<Event.Name, ActionCounts> perDayBucketActions = new HashMap<>(); BucketCounts blankBucket = new BucketCounts.Builder().withImpressionCounts(impressions) .withJointActionCounts(jointActions) .withActionCounts(perDayBucketActions).build(); Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (Map bucketRow : bucketRows) { Bucket.Label externalLabel = Bucket.Label.valueOf((String) bucketRow.get("label")); BucketCounts bucket = blankBucket.clone(); bucket.setLabel(externalLabel); buckets.put(externalLabel, bucket); } return buckets; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } }
DatabaseAnalytics implements AnalyticsRepository { @Override public Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID) throws RepositoryException { try { List<Map> bucketRows = transaction.select("select label from bucket where experiment_id=?", experimentID); Counts impressions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Counts jointActions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Map<Event.Name, ActionCounts> perDayBucketActions = new HashMap<>(); BucketCounts blankBucket = new BucketCounts.Builder().withImpressionCounts(impressions) .withJointActionCounts(jointActions) .withActionCounts(perDayBucketActions).build(); Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (Map bucketRow : bucketRows) { Bucket.Label externalLabel = Bucket.Label.valueOf((String) bucketRow.get("label")); BucketCounts bucket = blankBucket.clone(); bucket.setLabel(externalLabel); buckets.put(externalLabel, bucket); } return buckets; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } } }
DatabaseAnalytics implements AnalyticsRepository { @Override public Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID) throws RepositoryException { try { List<Map> bucketRows = transaction.select("select label from bucket where experiment_id=?", experimentID); Counts impressions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Counts jointActions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Map<Event.Name, ActionCounts> perDayBucketActions = new HashMap<>(); BucketCounts blankBucket = new BucketCounts.Builder().withImpressionCounts(impressions) .withJointActionCounts(jointActions) .withActionCounts(perDayBucketActions).build(); Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (Map bucketRow : bucketRows) { Bucket.Label externalLabel = Bucket.Label.valueOf((String) bucketRow.get("label")); BucketCounts bucket = blankBucket.clone(); bucket.setLabel(externalLabel); buckets.put(externalLabel, bucket); } return buckets; } catch (Exception e) { throw new RepositoryException("error reading actions rows from MySQL", e); } } @Inject  DatabaseAnalytics(TransactionFactory transactionFactory, Flyway flyway); }
DatabaseAnalytics implements AnalyticsRepository { @Override public Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID) throws RepositoryException { try { List<Map> bucketRows = transaction.select("select label from bucket where experiment_id=?", experimentID); Counts impressions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Counts jointActions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Map<Event.Name, ActionCounts> perDayBucketActions = new HashMap<>(); BucketCounts blankBucket = new BucketCounts.Builder().withImpressionCounts(impressions) .withJointActionCounts(jointActions) .withActionCounts(perDayBucketActions).build(); Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (Map bucketRow : bucketRows) { Bucket.Label externalLabel = Bucket.Label.valueOf((String) bucketRow.get("label")); BucketCounts bucket = blankBucket.clone(); bucket.setLabel(externalLabel); buckets.put(externalLabel, bucket); } return buckets; } 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 Map<Bucket.Label, BucketCounts> getEmptyBuckets(Experiment.ID experimentID) throws RepositoryException { try { List<Map> bucketRows = transaction.select("select label from bucket where experiment_id=?", experimentID); Counts impressions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Counts jointActions = new Counts.Builder().withEventCount(0).withUniqueUserCount(0).build(); Map<Event.Name, ActionCounts> perDayBucketActions = new HashMap<>(); BucketCounts blankBucket = new BucketCounts.Builder().withImpressionCounts(impressions) .withJointActionCounts(jointActions) .withActionCounts(perDayBucketActions).build(); Map<Bucket.Label, BucketCounts> buckets = new HashMap<>(); for (Map bucketRow : bucketRows) { Bucket.Label externalLabel = Bucket.Label.valueOf((String) bucketRow.get("label")); BucketCounts bucket = blankBucket.clone(); bucket.setLabel(externalLabel); buckets.put(externalLabel, bucket); } return buckets; } 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);  }