ThriftQueryWeighers { public static QueryWeigher<Void> batchMutate(Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap) { long numRows = mutationMap.size(); return writeWeigher(numRows, () -> ThriftObjectSizeUtils.getApproximateSizeOfMutationMap(mutationMap)); } private  ThriftQueryWeighers(); static QueryWeigher<Map<ByteBuffer, List<ColumnOrSuperColumn>>> multigetSlice(List<ByteBuffer> keys); static QueryWeigher<List<KeySlice>> getRangeSlices(KeyRange keyRange); static QueryWeigher<Void> batchMutate(Map<ByteBuffer, Map<String, List<Mutation>>> mutationMap); static QueryWeigher<Void> remove(byte[] row); static final QueryWeigher<ColumnOrSuperColumn> GET; static final QueryWeigher<CqlResult> EXECUTE_CQL3_QUERY; }
@Test public void batchMutateWeigherReturnsCorrectNumRows() { Map<ByteBuffer, Map<String, List<Mutation>>> mutations = ImmutableMap.of( BYTES1, ImmutableMap.of( "table1", ImmutableList.of(MUTATION, MUTATION), "table2", ImmutableList.of(MUTATION)), BYTES2, ImmutableMap.of( "table1", ImmutableList.of(MUTATION))); long actualNumRows = ThriftQueryWeighers.batchMutate(mutations).weighSuccess(null, TIME_TAKEN) .numDistinctRows(); assertThat(actualNumRows).isEqualTo(2); }
@Test public void batchMutateWeigherReturnsSameAsSuccessForFailure() { Map<ByteBuffer, Map<String, List<Mutation>>> mutations = ImmutableMap.of( BYTES1, ImmutableMap.of("foo", ImmutableList.of(MUTATION, MUTATION))); QueryWeigher<Void> weigher = ThriftQueryWeighers.batchMutate(mutations); QueryWeight expected = ThriftQueryWeighers.batchMutate(mutations).weighSuccess(null, TIME_TAKEN); QueryWeight actual = weigher.weighFailure(new RuntimeException(), TIME_TAKEN); assertThat(actual).isEqualTo(expected); }