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