Client { public void put(String tableName, Put put) { Iterable<CKeyValue> keyValueList = put.getKeyValueList(); List<CKeyValue> indexValues = new ArrayList<CKeyValue>(); for (Index index : getIndices()) { indexValues.clear(); for (CKeyValue keyValue : keyValueList) { if (Bytes.compareTo(index.getColumnFamily(), keyValue.getFamily()) == 0) { if (Bytes.compareTo(index.getColumnQualifier(), keyValue.getQualifier()) == 0) { indexValues.add(keyValue); } } } index.handlePut(new Put(indexValues)); } DatabaseAdapter db = getDatabaseAdapter(); if (!db.verify()) throw new RuntimeException( "Could not connect to the database to make the put of the actual value. Index may be corrupt."); db.getTableAdapter(tableName).put(put); } Client(Configuration conf); void put(String tableName, Put put); HashMap<String, Index> getIndexMap(); Iterator<Result> query(Constraint query); Index[] getIndices(); Index[] getIndicesForTable(String tableName); Index getIndexByName(String string); Index[] getIndicesForColumn(String table, byte[] family,
      byte[] qualifier); void addIndex(Index index); Configuration getConf(); static void setDatabase(DatabaseAdapter db, Configuration conf); static void setDatabaseAdapter(Configuration conf,
      Class<? extends DatabaseAdapter> adapterClass); boolean tableExists(String tableName); boolean verify();  }
@Test public void testPut() throws Exception { TableAdapter primaryTable = createMock(TableAdapter.class); Client c = PowerMock.createPartialMock(Client.class, "getIndices", "getDatabaseAdapter"); CKeyValue keyValue = new CKeyValue("rowid".getBytes(), "f".getBytes(), "q".getBytes(), "v".getBytes()); ArrayList<CKeyValue> keyValueList = new ArrayList<CKeyValue>(); keyValueList.add(keyValue); Put put = new Put(keyValueList); Put put2 = new Put(keyValue); put.hashCode(); put2.equals(""); Index mockIndex = EasyMock.createMock(Index.class); EasyMock.expect(c.getIndices()).andReturn(new Index[] { mockIndex }); EasyMock.expect(mockIndex.getColumnFamily()).andReturn("f".getBytes()); EasyMock.expect(mockIndex.getColumnQualifier()).andReturn("q".getBytes()); mockIndex.handlePut(EasyMock.anyObject(Put.class)); DatabaseAdapter databaseAdapter = EasyMock .createMock(DatabaseAdapter.class); EasyMock.expect(databaseAdapter.verify()).andReturn(true); PowerMock.expectPrivate(c, "getDatabaseAdapter").andReturn(databaseAdapter); EasyMock.expect(databaseAdapter.getTableAdapter("foo")).andReturn( primaryTable); primaryTable.put(put); PowerMock.replayAll(mockIndex, primaryTable, databaseAdapter); c.put("foo", put); EasyMock.verify(primaryTable); }