View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.coprocessor;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.hadoop.conf.Configuration;
26  import org.apache.hadoop.hbase.HBaseTestingUtility;
27  import org.apache.hadoop.hbase.HConstants;
28  import org.apache.hadoop.hbase.testclassification.MediumTests;
29  import org.apache.hadoop.hbase.TableName;
30  import org.apache.hadoop.hbase.client.Durability;
31  import org.apache.hadoop.hbase.client.HTable;
32  import org.apache.hadoop.hbase.client.Put;
33  import org.apache.hadoop.hbase.client.Scan;
34  import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
35  import org.apache.hadoop.hbase.client.coprocessor.DoubleColumnInterpreter;
36  import org.apache.hadoop.hbase.filter.Filter;
37  import org.apache.hadoop.hbase.filter.PrefixFilter;
38  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.DoubleMsg;
39  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.EmptyMsg;
40  import org.apache.hadoop.hbase.util.Bytes;
41  import org.junit.AfterClass;
42  import org.junit.BeforeClass;
43  import org.junit.Test;
44  import org.junit.experimental.categories.Category;
45  
46  /**
47   * A test class to test DoubleColumnInterpreter for AggregateProtocol
48   */
49  @Category(MediumTests.class)
50  public class TestDoubleColumnInterpreter {
51    protected static Log myLog = LogFactory.getLog(TestDoubleColumnInterpreter.class);
52  
53    /**
54     * Creating the test infrastructure.
55     */
56    private static final TableName TEST_TABLE = TableName.valueOf("TestTable");
57    private static final byte[] TEST_FAMILY = Bytes.toBytes("TestFamily");
58    private static final byte[] TEST_QUALIFIER = Bytes.toBytes("TestQualifier");
59    private static final byte[] TEST_MULTI_CQ = Bytes.toBytes("TestMultiCQ");
60  
61    private static byte[] ROW = Bytes.toBytes("testRow");
62    private static final int ROWSIZE = 20;
63    private static final int rowSeperator1 = 5;
64    private static final int rowSeperator2 = 12;
65    private static byte[][] ROWS = makeN(ROW, ROWSIZE);
66  
67    private static HBaseTestingUtility util = new HBaseTestingUtility();
68    private static Configuration conf = util.getConfiguration();
69  
70    /**
71     * A set up method to start the test cluster. AggregateProtocolImpl is registered and will be
72     * loaded during region startup.
73     * @throws Exception
74     */
75    @BeforeClass
76    public static void setupBeforeClass() throws Exception {
77  
78      conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
79        "org.apache.hadoop.hbase.coprocessor.AggregateImplementation");
80  
81      util.startMiniCluster(2);
82      final byte[][] SPLIT_KEYS = new byte[][] { ROWS[rowSeperator1], ROWS[rowSeperator2] };
83      HTable table = util.createTable(TEST_TABLE, TEST_FAMILY, SPLIT_KEYS);
84      /**
85       * The testtable has one CQ which is always populated and one variable CQ for each row rowkey1:
86       * CF:CQ CF:CQ1 rowKey2: CF:CQ CF:CQ2
87       */
88      for (int i = 0; i < ROWSIZE; i++) {
89        Put put = new Put(ROWS[i]);
90        put.setDurability(Durability.SKIP_WAL);
91        Double d = new Double(i);
92        put.add(TEST_FAMILY, TEST_QUALIFIER, Bytes.toBytes(d));
93        table.put(put);
94        Put p2 = new Put(ROWS[i]);
95        put.setDurability(Durability.SKIP_WAL);
96        p2.add(TEST_FAMILY, Bytes.add(TEST_MULTI_CQ, Bytes.toBytes(d)), Bytes.toBytes(d * 0.10));
97        table.put(p2);
98      }
99      table.close();
100   }
101 
102   /**
103    * Shutting down the cluster
104    * @throws Exception
105    */
106   @AfterClass
107   public static void tearDownAfterClass() throws Exception {
108     util.shutdownMiniCluster();
109   }
110 
111   /**
112    * an infrastructure method to prepare rows for the testtable.
113    * @param base
114    * @param n
115    * @return
116    */
117   private static byte[][] makeN(byte[] base, int n) {
118     byte[][] ret = new byte[n][];
119     for (int i = 0; i < n; i++) {
120       ret[i] = Bytes.add(base, Bytes.toBytes(i));
121     }
122     return ret;
123   }
124 
125   /**
126    * ****************** Test cases for Median **********************
127    */
128   /**
129    * @throws Throwable
130    */
131   @Test(timeout = 300000)
132   public void testMedianWithValidRange() throws Throwable {
133     AggregationClient aClient = new AggregationClient(conf);
134     Scan scan = new Scan();
135     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
136     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
137         new DoubleColumnInterpreter();
138     double median = aClient.median(TEST_TABLE, ci, scan);
139     assertEquals(8.00, median, 0.00);
140   }
141 
142   /**
143    * ***************Test cases for Maximum *******************
144    */
145 
146   /**
147    * give max for the entire table.
148    * @throws Throwable
149    */
150   @Test(timeout = 300000)
151   public void testMaxWithValidRange() throws Throwable {
152     AggregationClient aClient = new AggregationClient(conf);
153     Scan scan = new Scan();
154     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
155     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
156         new DoubleColumnInterpreter();
157     double maximum = aClient.max(TEST_TABLE, ci, scan);
158     assertEquals(19.00, maximum, 0.00);
159   }
160 
161   /**
162    * @throws Throwable
163    */
164   @Test(timeout = 300000)
165   public void testMaxWithValidRange2() throws Throwable {
166     AggregationClient aClient = new AggregationClient(conf);
167     Scan scan = new Scan();
168     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
169     scan.setStartRow(ROWS[5]);
170     scan.setStopRow(ROWS[15]);
171     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
172         new DoubleColumnInterpreter();
173     double max = aClient.max(TEST_TABLE, ci, scan);
174     assertEquals(14.00, max, 0.00);
175   }
176 
177   @Test(timeout = 300000)
178   public void testMaxWithValidRangeWithNoCQ() throws Throwable {
179     AggregationClient aClient = new AggregationClient(conf);
180     Scan scan = new Scan();
181     scan.addFamily(TEST_FAMILY);
182     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
183         new DoubleColumnInterpreter();
184     double maximum = aClient.max(TEST_TABLE, ci, scan);
185     assertEquals(19.00, maximum, 0.00);
186   }
187 
188   @Test(timeout = 300000)
189   public void testMaxWithValidRange2WithNoCQ() throws Throwable {
190     AggregationClient aClient = new AggregationClient(conf);
191     Scan scan = new Scan();
192     scan.addFamily(TEST_FAMILY);
193     scan.setStartRow(ROWS[6]);
194     scan.setStopRow(ROWS[7]);
195     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
196         new DoubleColumnInterpreter();
197     double max = aClient.max(TEST_TABLE, ci, scan);
198     assertEquals(6.00, max, 0.00);
199   }
200 
201   @Test(timeout = 300000)
202   public void testMaxWithValidRangeWithNullCF() {
203     AggregationClient aClient = new AggregationClient(conf);
204     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
205         new DoubleColumnInterpreter();
206     Scan scan = new Scan();
207     Double max = null;
208     try {
209       max = aClient.max(TEST_TABLE, ci, scan);
210     } catch (Throwable e) {
211       max = null;
212     }
213     assertEquals(null, max);// CP will throw an IOException about the
214     // null column family, and max will be set to 0
215   }
216 
217   @Test(timeout = 300000)
218   public void testMaxWithInvalidRange() {
219     AggregationClient aClient = new AggregationClient(conf);
220     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
221         new DoubleColumnInterpreter();
222     Scan scan = new Scan();
223     scan.setStartRow(ROWS[4]);
224     scan.setStopRow(ROWS[2]);
225     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
226     double max = Double.MIN_VALUE;
227     ;
228     try {
229       max = aClient.max(TEST_TABLE, ci, scan);
230     } catch (Throwable e) {
231       max = 0.00;
232     }
233     assertEquals(0.00, max, 0.00);// control should go to the catch block
234   }
235 
236   @Test(timeout = 300000)
237   public void testMaxWithInvalidRange2() throws Throwable {
238     double max = Double.MIN_VALUE;
239     Scan scan = new Scan();
240     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
241     scan.setStartRow(ROWS[4]);
242     scan.setStopRow(ROWS[4]);
243     try {
244       AggregationClient aClient = new AggregationClient(conf);
245       final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
246           new DoubleColumnInterpreter();
247       max = aClient.max(TEST_TABLE, ci, scan);
248     } catch (Exception e) {
249       max = 0.00;
250     }
251     assertEquals(0.00, max, 0.00);// control should go to the catch block
252   }
253 
254   @Test(timeout = 300000)
255   public void testMaxWithFilter() throws Throwable {
256     Double max = 0.00d;
257     AggregationClient aClient = new AggregationClient(conf);
258     Scan scan = new Scan();
259     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
260     Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
261     scan.setFilter(f);
262     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
263         new DoubleColumnInterpreter();
264     max = aClient.max(TEST_TABLE, ci, scan);
265     assertEquals(null, max);
266   }
267 
268   /**
269    * **************************Test cases for Minimum ***********************
270    */
271 
272   /**
273    * @throws Throwable
274    */
275   @Test(timeout = 300000)
276   public void testMinWithValidRange() throws Throwable {
277     AggregationClient aClient = new AggregationClient(conf);
278     Scan scan = new Scan();
279     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
280     scan.setStartRow(HConstants.EMPTY_START_ROW);
281     scan.setStopRow(HConstants.EMPTY_END_ROW);
282     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
283         new DoubleColumnInterpreter();
284     double min = aClient.min(TEST_TABLE, ci, scan);
285     assertEquals(0.00, min, 0.00);
286   }
287 
288   /**
289    * @throws Throwable
290    */
291   @Test(timeout = 300000)
292   public void testMinWithValidRange2() throws Throwable {
293     AggregationClient aClient = new AggregationClient(conf);
294     Scan scan = new Scan();
295     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
296     scan.setStartRow(ROWS[5]);
297     scan.setStopRow(ROWS[15]);
298     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
299         new DoubleColumnInterpreter();
300     double min = aClient.min(TEST_TABLE, ci, scan);
301     assertEquals(5.00, min, 0.00);
302   }
303 
304   @Test(timeout = 300000)
305   public void testMinWithValidRangeWithNoCQ() throws Throwable {
306     AggregationClient aClient = new AggregationClient(conf);
307     Scan scan = new Scan();
308     scan.addFamily(TEST_FAMILY);
309     scan.setStartRow(HConstants.EMPTY_START_ROW);
310     scan.setStopRow(HConstants.EMPTY_END_ROW);
311     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
312         new DoubleColumnInterpreter();
313     double min = aClient.min(TEST_TABLE, ci, scan);
314     assertEquals(0.00, min, 0.00);
315   }
316 
317   @Test(timeout = 300000)
318   public void testMinWithValidRange2WithNoCQ() throws Throwable {
319     AggregationClient aClient = new AggregationClient(conf);
320     Scan scan = new Scan();
321     scan.addFamily(TEST_FAMILY);
322     scan.setStartRow(ROWS[6]);
323     scan.setStopRow(ROWS[7]);
324     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
325         new DoubleColumnInterpreter();
326     double min = aClient.min(TEST_TABLE, ci, scan);
327     assertEquals(0.60, min, 0.001);
328   }
329 
330   @Test(timeout = 300000)
331   public void testMinWithValidRangeWithNullCF() {
332     AggregationClient aClient = new AggregationClient(conf);
333     Scan scan = new Scan();
334     scan.setStartRow(ROWS[5]);
335     scan.setStopRow(ROWS[15]);
336     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
337         new DoubleColumnInterpreter();
338     Double min = null;
339     try {
340       min = aClient.min(TEST_TABLE, ci, scan);
341     } catch (Throwable e) {
342       min = null;
343     }
344     assertEquals(null, min);// CP will throw an IOException about the
345     // null column family, and min will be set to 0
346   }
347 
348   @Test(timeout = 300000)
349   public void testMinWithInvalidRange() {
350     AggregationClient aClient = new AggregationClient(conf);
351     Double min = null;
352     Scan scan = new Scan();
353     scan.addFamily(TEST_FAMILY);
354     scan.setStartRow(ROWS[4]);
355     scan.setStopRow(ROWS[2]);
356     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
357         new DoubleColumnInterpreter();
358     try {
359       min = aClient.min(TEST_TABLE, ci, scan);
360     } catch (Throwable e) {
361     }
362     assertEquals(null, min);// control should go to the catch block
363   }
364 
365   @Test(timeout = 300000)
366   public void testMinWithInvalidRange2() {
367     AggregationClient aClient = new AggregationClient(conf);
368     Scan scan = new Scan();
369     scan.addFamily(TEST_FAMILY);
370     scan.setStartRow(ROWS[6]);
371     scan.setStopRow(ROWS[6]);
372     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
373         new DoubleColumnInterpreter();
374     Double min = null;
375     try {
376       min = aClient.min(TEST_TABLE, ci, scan);
377     } catch (Throwable e) {
378     }
379     assertEquals(null, min);// control should go to the catch block
380   }
381 
382   @Test(timeout = 300000)
383   public void testMinWithFilter() throws Throwable {
384     AggregationClient aClient = new AggregationClient(conf);
385     Scan scan = new Scan();
386     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
387     Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
388     scan.setFilter(f);
389     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
390         new DoubleColumnInterpreter();
391     Double min = null;
392     min = aClient.min(TEST_TABLE, ci, scan);
393     assertEquals(null, min);
394   }
395 
396   /**
397    * *************** Test cases for Sum *********************
398    */
399   /**
400    * @throws Throwable
401    */
402   @Test(timeout = 300000)
403   public void testSumWithValidRange() throws Throwable {
404     AggregationClient aClient = new AggregationClient(conf);
405     Scan scan = new Scan();
406     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
407     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
408         new DoubleColumnInterpreter();
409     double sum = aClient.sum(TEST_TABLE, ci, scan);
410     assertEquals(190.00, sum, 0.00);
411   }
412 
413   /**
414    * @throws Throwable
415    */
416   @Test(timeout = 300000)
417   public void testSumWithValidRange2() throws Throwable {
418     AggregationClient aClient = new AggregationClient(conf);
419     Scan scan = new Scan();
420     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
421     scan.setStartRow(ROWS[5]);
422     scan.setStopRow(ROWS[15]);
423     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
424         new DoubleColumnInterpreter();
425     double sum = aClient.sum(TEST_TABLE, ci, scan);
426     assertEquals(95.00, sum, 0.00);
427   }
428 
429   @Test(timeout = 300000)
430   public void testSumWithValidRangeWithNoCQ() throws Throwable {
431     AggregationClient aClient = new AggregationClient(conf);
432     Scan scan = new Scan();
433     scan.addFamily(TEST_FAMILY);
434     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
435         new DoubleColumnInterpreter();
436     double sum = aClient.sum(TEST_TABLE, ci, scan);
437     assertEquals(209.00, sum, 0.00); // 190 + 19
438   }
439 
440   @Test(timeout = 300000)
441   public void testSumWithValidRange2WithNoCQ() throws Throwable {
442     AggregationClient aClient = new AggregationClient(conf);
443     Scan scan = new Scan();
444     scan.addFamily(TEST_FAMILY);
445     scan.setStartRow(ROWS[6]);
446     scan.setStopRow(ROWS[7]);
447     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
448         new DoubleColumnInterpreter();
449     double sum = aClient.sum(TEST_TABLE, ci, scan);
450     assertEquals(6.60, sum, 0.00); // 6 + 60
451   }
452 
453   @Test(timeout = 300000)
454   public void testSumWithValidRangeWithNullCF() {
455     AggregationClient aClient = new AggregationClient(conf);
456     Scan scan = new Scan();
457     scan.setStartRow(ROWS[6]);
458     scan.setStopRow(ROWS[7]);
459     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
460         new DoubleColumnInterpreter();
461     Double sum = null;
462     try {
463       sum = aClient.sum(TEST_TABLE, ci, scan);
464     } catch (Throwable e) {
465     }
466     assertEquals(null, sum);// CP will throw an IOException about the
467     // null column family, and max will be set to 0
468   }
469 
470   @Test(timeout = 300000)
471   public void testSumWithInvalidRange() {
472     AggregationClient aClient = new AggregationClient(conf);
473     Scan scan = new Scan();
474     scan.addFamily(TEST_FAMILY);
475     scan.setStartRow(ROWS[6]);
476     scan.setStopRow(ROWS[2]);
477     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
478         new DoubleColumnInterpreter();
479     Double sum = null;
480     try {
481       sum = aClient.sum(TEST_TABLE, ci, scan);
482     } catch (Throwable e) {
483     }
484     assertEquals(null, sum);// control should go to the catch block
485   }
486 
487   @Test(timeout = 300000)
488   public void testSumWithFilter() throws Throwable {
489     AggregationClient aClient = new AggregationClient(conf);
490     Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
491     Scan scan = new Scan();
492     scan.addFamily(TEST_FAMILY);
493     scan.setFilter(f);
494     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
495         new DoubleColumnInterpreter();
496     Double sum = null;
497     sum = aClient.sum(TEST_TABLE, ci, scan);
498     assertEquals(null, sum);
499   }
500 
501   /**
502    * ****************************** Test Cases for Avg **************
503    */
504   /**
505    * @throws Throwable
506    */
507   @Test(timeout = 300000)
508   public void testAvgWithValidRange() throws Throwable {
509     AggregationClient aClient = new AggregationClient(conf);
510     Scan scan = new Scan();
511     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
512     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
513         new DoubleColumnInterpreter();
514     double avg = aClient.avg(TEST_TABLE, ci, scan);
515     assertEquals(9.5, avg, 0);
516   }
517 
518   /**
519    * @throws Throwable
520    */
521   @Test(timeout = 300000)
522   public void testAvgWithValidRange2() throws Throwable {
523     AggregationClient aClient = new AggregationClient(conf);
524     Scan scan = new Scan();
525     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
526     scan.setStartRow(ROWS[5]);
527     scan.setStopRow(ROWS[15]);
528     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci =
529         new DoubleColumnInterpreter();
530     double avg = aClient.avg(TEST_TABLE, ci, scan);
531     assertEquals(9.5, avg, 0);
532   }
533 
534   @Test(timeout = 300000)
535   public void testAvgWithValidRangeWithNoCQ() throws Throwable {
536     AggregationClient aClient = new AggregationClient(conf);
537     Scan scan = new Scan();
538     scan.addFamily(TEST_FAMILY);
539     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
540         new DoubleColumnInterpreter();
541     double avg = aClient.avg(TEST_TABLE, ci, scan);
542     assertEquals(10.45, avg, 0.01);
543   }
544 
545   @Test(timeout = 300000)
546   public void testAvgWithValidRange2WithNoCQ() throws Throwable {
547     AggregationClient aClient = new AggregationClient(conf);
548     Scan scan = new Scan();
549     scan.addFamily(TEST_FAMILY);
550     scan.setStartRow(ROWS[6]);
551     scan.setStopRow(ROWS[7]);
552     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
553         new DoubleColumnInterpreter();
554     double avg = aClient.avg(TEST_TABLE, ci, scan);
555     assertEquals(6 + 0.60, avg, 0);
556   }
557 
558   @Test(timeout = 300000)
559   public void testAvgWithValidRangeWithNullCF() {
560     AggregationClient aClient = new AggregationClient(conf);
561     Scan scan = new Scan();
562     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
563         new DoubleColumnInterpreter();
564     Double avg = null;
565     try {
566       avg = aClient.avg(TEST_TABLE, ci, scan);
567     } catch (Throwable e) {
568     }
569     assertEquals(null, avg);// CP will throw an IOException about the
570     // null column family, and max will be set to 0
571   }
572 
573   @Test(timeout = 300000)
574   public void testAvgWithInvalidRange() {
575     AggregationClient aClient = new AggregationClient(conf);
576     Scan scan = new Scan();
577     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
578     scan.setStartRow(ROWS[5]);
579     scan.setStopRow(ROWS[1]);
580     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
581         new DoubleColumnInterpreter();
582     Double avg = null;
583     try {
584       avg = aClient.avg(TEST_TABLE, ci, scan);
585     } catch (Throwable e) {
586     }
587     assertEquals(null, avg);// control should go to the catch block
588   }
589 
590   @Test(timeout = 300000)
591   public void testAvgWithFilter() throws Throwable {
592     AggregationClient aClient = new AggregationClient(conf);
593     Scan scan = new Scan();
594     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
595     Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
596     scan.setFilter(f);
597     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
598         new DoubleColumnInterpreter();
599     Double avg = null;
600     avg = aClient.avg(TEST_TABLE, ci, scan);
601     assertEquals(Double.NaN, avg, 0);
602   }
603 
604   /**
605    * ****************** Test cases for STD **********************
606    */
607   /**
608    * @throws Throwable
609    */
610   @Test(timeout = 300000)
611   public void testStdWithValidRange() throws Throwable {
612     AggregationClient aClient = new AggregationClient(conf);
613     Scan scan = new Scan();
614     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
615     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
616         new DoubleColumnInterpreter();
617     double std = aClient.std(TEST_TABLE, ci, scan);
618     assertEquals(5.766, std, 0.05d);
619   }
620 
621   /**
622    * need to change this
623    * @throws Throwable
624    */
625   @Test(timeout = 300000)
626   public void testStdWithValidRange2() throws Throwable {
627     AggregationClient aClient = new AggregationClient(conf);
628     Scan scan = new Scan();
629     scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
630     scan.setStartRow(ROWS[5]);
631     scan.setStopRow(ROWS[15]);
632     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
633         new DoubleColumnInterpreter();
634     double std = aClient.std(TEST_TABLE, ci, scan);
635     assertEquals(2.87, std, 0.05d);
636   }
637 
638   /**
639    * need to change this
640    * @throws Throwable
641    */
642   @Test(timeout = 300000)
643   public void testStdWithValidRangeWithNoCQ() throws Throwable {
644     AggregationClient aClient = new AggregationClient(conf);
645     Scan scan = new Scan();
646     scan.addFamily(TEST_FAMILY);
647     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
648         new DoubleColumnInterpreter();
649     double std = aClient.std(TEST_TABLE, ci, scan);
650     assertEquals(6.342, std, 0.05d);
651   }
652 
653   @Test(timeout = 300000)
654   public void testStdWithValidRange2WithNoCQ() throws Throwable {
655     AggregationClient aClient = new AggregationClient(conf);
656     Scan scan = new Scan();
657     scan.addFamily(TEST_FAMILY);
658     scan.setStartRow(ROWS[6]);
659     scan.setStopRow(ROWS[7]);
660     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
661         new DoubleColumnInterpreter();
662     double std = aClient.std(TEST_TABLE, ci, scan);
663     System.out.println("std is:" + std);
664     assertEquals(0, std, 0.05d);
665   }
666 
667   @Test(timeout = 300000)
668   public void testStdWithValidRangeWithNullCF() {
669     AggregationClient aClient = new AggregationClient(conf);
670     Scan scan = new Scan();
671     scan.setStartRow(ROWS[6]);
672     scan.setStopRow(ROWS[17]);
673     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
674         new DoubleColumnInterpreter();
675     Double std = null;
676     try {
677       std = aClient.std(TEST_TABLE, ci, scan);
678     } catch (Throwable e) {
679     }
680     assertEquals(null, std);// CP will throw an IOException about the
681     // null column family, and max will be set to 0
682   }
683 
684   @Test
685   public void testStdWithInvalidRange() {
686     AggregationClient aClient = new AggregationClient(conf);
687     Scan scan = new Scan();
688     scan.addFamily(TEST_FAMILY);
689     scan.setStartRow(ROWS[6]);
690     scan.setStopRow(ROWS[1]);
691     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
692         new DoubleColumnInterpreter();
693     Double std = null;
694     try {
695       std = aClient.std(TEST_TABLE, ci, scan);
696     } catch (Throwable e) {
697     }
698     assertEquals(null, std);// control should go to the catch block
699   }
700 
701   @Test(timeout = 300000)
702   public void testStdWithFilter() throws Throwable {
703     AggregationClient aClient = new AggregationClient(conf);
704     Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
705     Scan scan = new Scan();
706     scan.addFamily(TEST_FAMILY);
707     scan.setFilter(f);
708     final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg> ci = 
709         new DoubleColumnInterpreter();
710     Double std = null;
711     std = aClient.std(TEST_TABLE, ci, scan);
712     assertEquals(Double.NaN, std, 0);
713   }
714 }