@Test
 public void testTableExists() throws IOException {
   final KijiTableLayout simple =
       KijiTableLayout.newLayout(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));
   final Kiji kiji = new InstanceBuilder(getKiji()).withTable("table", simple).build();
   assertTrue(kiji.getMetaTable().tableExists(simple.getDesc().getName()));
   assertFalse(kiji.getMetaTable().tableExists("faketablename"));
 }
  @Test
  public void testSetLayout() throws Exception {
    final TableLayoutDesc layoutDesc = KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE);
    final KijiTableLayout layout = KijiTableLayout.newLayout(layoutDesc);

    final Get expectedGet =
        new Get(Bytes.toBytes(layout.getDesc().getName()))
            .addColumn(
                Bytes.toBytes(mFamily), Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT))
            .setMaxVersions(1);
    final Result expectedGetResult = new Result(Collections.<KeyValue>emptyList());
    expect(mHTable.get(eqGet(expectedGet))).andReturn(expectedGetResult);

    final Put expectedPut =
        new Put(Bytes.toBytes(layout.getDesc().getName()))
            .add(
                Bytes.toBytes(mFamily),
                Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_UPDATE),
                encode(layoutDesc))
            .add(
                Bytes.toBytes(mFamily),
                Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT),
                encode(layout.getDesc()))
            .add(
                Bytes.toBytes(mFamily),
                Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT_ID),
                Bytes.toBytes("1"));
    mHTable.put(eqPut(expectedPut));

    replay(mHTable);

    mDb.updateTableLayout(layout.getDesc().getName(), layoutDesc);

    verify(mHTable);
  }
  @Test
  public void testGetLayout() throws Exception {
    final KijiTableLayout version1 =
        KijiTableLayout.newLayout(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));

    final Get expectedGet =
        new Get(Bytes.toBytes(version1.getDesc().getName()))
            .addColumn(
                Bytes.toBytes(mFamily), Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT))
            .setMaxVersions(1);
    final List<KeyValue> kvs = new ArrayList<KeyValue>();
    kvs.add(
        new KeyValue(
            Bytes.toBytes(version1.getDesc().getName()),
            Bytes.toBytes(mFamily),
            Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT),
            1L,
            encode(version1.getDesc())));
    final Result cannedResult = new Result(kvs);
    expect(mHTable.get(eqGet(expectedGet))).andReturn(cannedResult);

    replay(mHTable);

    assertEquals(version1, mDb.getTableLayout(version1.getDesc().getName().toString()));

    verify(mHTable);
  }
Ejemplo n.º 4
0
 /**
  * Creates an initial table layout from the specified JSON resource.
  *
  * @param resourcePath Path of the resource to load the JSON descriptor from.
  * @return an initial table layout constructed from the specified JSON resource.
  * @throws IOException on I/O error.
  */
 public static KijiTableLayout getTableLayout(String resourcePath) throws IOException {
   return KijiTableLayout.newLayout(getLayout(resourcePath));
 }
  @Test
  public void testGetMulitipleLayouts() throws Exception {
    final KijiTableLayout layout1 =
        KijiTableLayout.newLayout(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));
    final KijiTableLayout layout2 =
        KijiTableLayout.newLayout(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));
    final KijiTableLayout layout3 =
        KijiTableLayout.newLayout(KijiTableLayouts.getLayout(KijiTableLayouts.SIMPLE));

    layout1.getDesc().setVersion("layout-1.0");
    layout2.getDesc().setVersion("layout-1.0.1");
    layout3.getDesc().setVersion("layout-1.1");

    final Get expectedGet =
        new Get(Bytes.toBytes(layout1.getDesc().getName()))
            .addColumn(
                Bytes.toBytes(mFamily), Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT))
            .setMaxVersions(2);

    final List<KeyValue> kvs = new ArrayList<KeyValue>();
    kvs.add(
        new KeyValue(
            Bytes.toBytes(layout3.getDesc().getName()),
            Bytes.toBytes(mFamily),
            Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT),
            3L,
            encode(layout3.getDesc())));
    kvs.add(
        new KeyValue(
            Bytes.toBytes(layout2.getDesc().getName()),
            Bytes.toBytes(mFamily),
            Bytes.toBytes(HBaseTableLayoutDatabase.QUALIFIER_LAYOUT),
            2L,
            encode(layout2.getDesc())));
    Result cannedResult = new Result(kvs);
    expect(mHTable.get(eqGet(expectedGet))).andReturn(cannedResult);

    replay(mHTable);

    NavigableMap<Long, KijiTableLayout> timedLayouts =
        mDb.getTimedTableLayoutVersions(layout1.getDesc().getName().toString(), 2);
    Set<Long> timestamps = timedLayouts.keySet();
    Iterator<Long> iterator = timestamps.iterator();

    assertEquals(2, timedLayouts.size());
    long time2 = iterator.next();
    long time3 = iterator.next();
    assertEquals(2L, time2);
    assertEquals(layout2, timedLayouts.get(time2));
    assertEquals(3L, time3);
    assertEquals(layout3, timedLayouts.get(time3));

    verify(mHTable);
  }