@Test
  public void test() throws Exception {
    log.info("You can ignore exceptions and scary stack traces from this test");
    IdService idService = new CachingIdService(5, new MapIdService(), "test");

    Configuration conf = getTestUtil().getConfiguration();
    HTablePool pool = new HTablePool(conf, Integer.MAX_VALUE);

    DbHarness<LongOp> dbHarness =
        new HBaseDbHarness<LongOp>(
            pool,
            "XY".getBytes(),
            "nonexistentTable".getBytes(),
            "nonexistentCf".getBytes(),
            LongOp.DESERIALIZER,
            idService,
            CommitType.INCREMENT,
            5,
            2,
            2,
            null);

    DataCube<LongOp> cube;

    Dimension<String> zipcode =
        new Dimension<String>("zipcode", new StringToBytesBucketer(), true, 5);

    Rollup zipRollup = new Rollup(zipcode);

    List<Dimension<?>> dimensions = ImmutableList.<Dimension<?>>of(zipcode);
    List<Rollup> rollups = ImmutableList.of(zipRollup);

    cube = new DataCube<LongOp>(dimensions, rollups);

    DataCubeIo<LongOp> dataCubeIo =
        new DataCubeIo<LongOp>(cube, dbHarness, 1, Long.MAX_VALUE, SyncLevel.BATCH_ASYNC);

    dataCubeIo.writeAsync(new LongOp(1), new WriteBuilder(cube).at(zipcode, "97212"));

    dataCubeIo.writeAsync(new LongOp(1), new WriteBuilder(cube).at(zipcode, "97212"));

    dataCubeIo.flush();

    try {
      dataCubeIo.writeAsync(new LongOp(1), new WriteBuilder(cube).at(zipcode, "97212"));
      Assert.fail("Cube should not have accepted more writes after an error!");
    } catch (AsyncException e) {
      // This exception *should* happen. Because we wrote to a nonexistent table.
      Assert.assertTrue(e.getCause().getCause().getCause() instanceof TableNotFoundException);
    }
  }
Example #2
0
 /** Get the number of hashtag occurrences in the given time bucket. */
 protected long getTagTimeCount(String hashtag, BucketType timeBucketType, DateTime dateTime)
     throws IOException, InterruptedException {
   Optional<LongOp> optCount =
       dataCubeIo.get(
           new ReadBuilder(dataCube)
               .at(tagsDimension, hashtag)
               .at(timeDimension, timeBucketType, dateTime));
   return unpackOrZero(optCount);
 }
Example #3
0
 /** Get the number of times that retweeterUser retweeted a tweet by sourceUser. */
 public long getRetweetsOfBy(String sourceUser, String retweeterUser)
     throws IOException, InterruptedException {
   Optional<LongOp> optCount =
       dataCubeIo.get(
           new ReadBuilder(dataCube)
               .at(retweetedFromDimension, sourceUser)
               .at(userDimension, retweeterUser));
   return unpackOrZero(optCount);
 }
Example #4
0
 /** Get the number of tweets sent by the given user on the given day. */
 public long getUserDayCount(String userName, DateTime day)
     throws InterruptedException, IOException {
   Optional<LongOp> optCount =
       dataCubeIo.get(
           new ReadBuilder(dataCube)
               .at(userDimension, userName)
               .at(timeDimension, HourDayMonthBucketer.days, day));
   return unpackOrZero(optCount);
 }
Example #5
0
  /**
   * Do all the increments necessary to add a tweet to the datacube. May not immediately flush to
   * the DB.
   */
  public void countTweet(Tweet tweet) throws IOException, InterruptedException, AsyncException {
    WriteBuilder writeBuilder =
        new WriteBuilder(dataCube)
            .at(timeDimension, tweet.time)
            .at(userDimension, tweet.username)
            .at(retweetedFromDimension, tweet.retweetedFrom.or(""))
            .at(tagsDimension, tweet.hashTags);
    Batch<LongOp> cubeUpdates = dataCube.getWrites(writeBuilder, new LongOp(1));

    dataCubeIo.writeAsync(cubeUpdates);
  }
Example #6
0
 /** Write all batched/cached changes to the backing database. */
 public void flush() throws InterruptedException {
   dataCubeIo.flush();
 }
Example #7
0
 /** Get the number of tweets that included the given hashtag. */
 public long getTagCount(String hashtag) throws IOException, InterruptedException {
   Optional<LongOp> optCount =
       dataCubeIo.get(new ReadBuilder(dataCube).at(tagsDimension, hashtag));
   return unpackOrZero(optCount);
 }
Example #8
0
 /** Get the total number of tweets sent by the given user. */
 public long getUserCount(String userName) throws InterruptedException, IOException {
   Optional<LongOp> optCount =
       dataCubeIo.get(new ReadBuilder(dataCube).at(userDimension, userName));
   return unpackOrZero(optCount);
 }
Example #9
0
 /** Get the total number of tweets. */
 public long getCount() throws InterruptedException, IOException {
   return dataCubeIo.get(new ReadBuilder(dataCube)).or(new LongOp(0)).getLong();
 }