Ejemplo n.º 1
0
  @Test
  public void testRetrieveAll() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    manager.storePolicy("user", "info:name", TestProducer.class, new NeverFreshen());
    manager.storePolicy("user", "info:visits", TestProducer.class, new NeverFreshen());

    LOG.info(KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString());

    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString(),
            "--do=retrieve-all"));

    assertEquals(
        "Freshness policy attached to column: info:visits\n"
            + "  Freshness policy class: org.kiji.scoring.lib.NeverFreshen\n"
            + "  Freshness policy state: \n"
            + "  Producer class: org.kiji.scoring.tools.TestFreshTool$TestProducer\n"
            + "Freshness policy attached to column: info:name\n"
            + "  Freshness policy class: org.kiji.scoring.lib.NeverFreshen\n"
            + "  Freshness policy state: \n"
            + "  Producer class: org.kiji.scoring.tools.TestFreshTool$TestProducer\n",
        mToolOutputStr);
  }
Ejemplo n.º 2
0
  @Test
  public void testUnregisterAll() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    manager.storePolicy("user", "info:name", TestProducer.class, new NeverFreshen());
    manager.storePolicy("user", "info:visits", TestProducer.class, new NeverFreshen());

    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString(),
            "--do=unregister-all"));
    assertEquals(0, manager.retrievePolicies("user").size());
    assertEquals("All freshness policies removed from table: user", mToolOutputStr);
  }
Ejemplo n.º 3
0
  @Test
  public void testValidate() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    manager.storePolicy("user", "info:name", TestProducer.class, new AlwaysFreshen());
    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString(),
            "--do=validate-all"));

    KijiFreshnessPolicyRecord record =
        KijiFreshnessPolicyRecord.newBuilder()
            .setRecordVersion(ProtocolVersion.parse("policyrecord-0.1").toCanonicalString())
            .setProducerClass(TestProducer.class.getName())
            .setFreshnessPolicyClass(AlwaysFreshen.class.getName())
            .setFreshnessPolicyState("")
            .build();

    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    final EncoderFactory encoderFactory = EncoderFactory.get();
    Encoder encoder = encoderFactory.directBinaryEncoder(outputStream, null);
    final DatumWriter<KijiFreshnessPolicyRecord> recordWriter =
        new SpecificDatumWriter<KijiFreshnessPolicyRecord>(KijiFreshnessPolicyRecord.SCHEMA$);
    recordWriter.write(record, encoder);
    getKiji()
        .getMetaTable()
        .putValue("user", "kiji.scoring.fresh.columnName", outputStream.toByteArray());

    assertEquals(
        BaseTool.FAILURE,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI()).withTableName("user").build().toString(),
            "--do=validate-all"));
    assertEquals(
        "Freshness policy attached to column: columnName is not valid.", mToolOutputLines[1]);
    assertEquals(
        "NO_FAMILY_IN_TABLE: java.lang.IllegalArgumentException: Table: user does not "
            + "contain family: columnName",
        mToolOutputLines[2]);
  }
Ejemplo n.º 4
0
  @Test
  public void testUnregister() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    manager.storePolicy("user", "info:name", TestProducer.class, new NeverFreshen());

    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI())
                .withTableName("user")
                .withColumnNames(Lists.newArrayList("info:name"))
                .build()
                .toString(),
            "--do=unregister"));
    assertEquals(null, manager.retrievePolicy("user", "info:name"));
    assertEquals("Freshness policy removed from column: info:name in table user", mToolOutputStr);
  }
Ejemplo n.º 5
0
  @Test
  public void testRegister() throws Exception {
    getKiji().createTable(KijiTableLayouts.getLayout(KijiTableLayouts.COUNTER_TEST));
    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            KijiURI.newBuilder(getKiji().getURI())
                .withTableName("user")
                .withColumnNames(Lists.newArrayList("info:name"))
                .build()
                .toString(),
            "--do=register",
            "--policy-class=org.kiji.scoring.lib.ShelfLife",
            "--policy-state={\"shelfLife\":10}",
            "--producer-class=org.kiji.scoring.tools.TestFreshTool$TestProducer"));

    final KijiFreshnessPolicyRecord record =
        KijiFreshnessPolicyRecord.newBuilder()
            .setRecordVersion("policyrecord-0.1.0")
            .setProducerClass(TestProducer.class.getName())
            .setFreshnessPolicyClass(
                Class.forName("org.kiji.scoring.lib.ShelfLife")
                    .asSubclass(KijiFreshnessPolicy.class)
                    .getName())
            .setFreshnessPolicyState("{\"shelfLife\":10}")
            .build();
    final KijiFreshnessManager manager = KijiFreshnessManager.create(getKiji());
    assertEquals(record, manager.retrievePolicy("user", "info:name"));
    assertEquals(
        "Freshness policy: org.kiji.scoring.lib.ShelfLife with state: {\"shelfLife\":10} "
            + "and producer: org.kiji.scoring.tools.TestFreshTool$TestProducer\n"
            + "attached to column: info:name in table: user",
        mToolOutputStr);

    // Test another ordering for arguments
    assertEquals(
        BaseTool.SUCCESS,
        runTool(
            new FreshTool(),
            "--do=register",
            KijiURI.newBuilder(getKiji().getURI())
                .withTableName("user")
                .withColumnNames(Lists.newArrayList("info:visits"))
                .build()
                .toString(),
            "--policy-state={\"shelfLife\":10}",
            "--producer-class=org.kiji.scoring.tools.TestFreshTool$TestProducer",
            "--policy-class=org.kiji.scoring.lib.ShelfLife"));

    final KijiFreshnessPolicyRecord record2 =
        KijiFreshnessPolicyRecord.newBuilder()
            .setRecordVersion("policyrecord-0.1.0")
            .setProducerClass(TestProducer.class.getName())
            .setFreshnessPolicyClass(
                Class.forName("org.kiji.scoring.lib.ShelfLife")
                    .asSubclass(KijiFreshnessPolicy.class)
                    .getName())
            .setFreshnessPolicyState("{\"shelfLife\":10}")
            .build();
    assertEquals(record2, manager.retrievePolicy("user", "info:visits"));
    assertEquals(
        "Freshness policy: org.kiji.scoring.lib.ShelfLife with state: {\"shelfLife\":10} "
            + "and producer: org.kiji.scoring.tools.TestFreshTool$TestProducer\n"
            + "attached to column: info:visits in table: user",
        mToolOutputStr);
  }