1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.io;
19  
20  import java.io.ByteArrayInputStream;
21  import java.io.ByteArrayOutputStream;
22  import java.io.DataInput;
23  import java.io.DataInputStream;
24  import java.io.DataOutput;
25  import java.io.DataOutputStream;
26  import java.io.IOException;
27  import java.io.Serializable;
28  import java.lang.reflect.Array;
29  import java.util.ArrayList;
30  import java.util.List;
31  import java.util.NavigableSet;
32  
33  import junit.framework.TestCase;
34  
35  import org.apache.hadoop.conf.Configuration;
36  import org.apache.hadoop.hbase.ClusterStatus;
37  import org.apache.hadoop.hbase.HBaseConfiguration;
38  import org.apache.hadoop.hbase.HColumnDescriptor;
39  import org.apache.hadoop.hbase.HConstants;
40  import org.apache.hadoop.hbase.HRegionInfo;
41  import org.apache.hadoop.hbase.HServerAddress;
42  import org.apache.hadoop.hbase.HServerInfo;
43  import org.apache.hadoop.hbase.HServerLoad;
44  import org.apache.hadoop.hbase.HServerLoadWithSeqIds;
45  import org.apache.hadoop.hbase.HTableDescriptor;
46  import org.apache.hadoop.hbase.KeyValue;
47  import org.apache.hadoop.hbase.SmallTests;
48  import org.apache.hadoop.hbase.client.Action;
49  import org.apache.hadoop.hbase.client.Append;
50  import org.apache.hadoop.hbase.client.Delete;
51  import org.apache.hadoop.hbase.client.Get;
52  import org.apache.hadoop.hbase.client.Increment;
53  import org.apache.hadoop.hbase.client.MultiAction;
54  import org.apache.hadoop.hbase.client.MultiResponse;
55  import org.apache.hadoop.hbase.client.Put;
56  import org.apache.hadoop.hbase.client.Result;
57  import org.apache.hadoop.hbase.client.Row;
58  import org.apache.hadoop.hbase.client.RowMutations;
59  import org.apache.hadoop.hbase.client.Scan;
60  import org.apache.hadoop.hbase.client.coprocessor.Exec;
61  import org.apache.hadoop.hbase.filter.BinaryComparator;
62  import org.apache.hadoop.hbase.filter.BitComparator;
63  import org.apache.hadoop.hbase.filter.ColumnCountGetFilter;
64  import org.apache.hadoop.hbase.filter.ColumnPrefixFilter;
65  import org.apache.hadoop.hbase.filter.ColumnRangeFilter;
66  import org.apache.hadoop.hbase.filter.CompareFilter;
67  import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
68  import org.apache.hadoop.hbase.filter.DependentColumnFilter;
69  import org.apache.hadoop.hbase.filter.Filter;
70  import org.apache.hadoop.hbase.filter.FilterBase;
71  import org.apache.hadoop.hbase.filter.FilterList;
72  import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;
73  import org.apache.hadoop.hbase.filter.InclusiveStopFilter;
74  import org.apache.hadoop.hbase.filter.KeyOnlyFilter;
75  import org.apache.hadoop.hbase.filter.PageFilter;
76  import org.apache.hadoop.hbase.filter.PrefixFilter;
77  import org.apache.hadoop.hbase.filter.QualifierFilter;
78  import org.apache.hadoop.hbase.filter.RandomRowFilter;
79  import org.apache.hadoop.hbase.filter.RowFilter;
80  import org.apache.hadoop.hbase.filter.SingleColumnValueExcludeFilter;
81  import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
82  import org.apache.hadoop.hbase.filter.SkipFilter;
83  import org.apache.hadoop.hbase.filter.ValueFilter;
84  import org.apache.hadoop.hbase.filter.WhileMatchFilter;
85  import org.apache.hadoop.hbase.filter.WritableByteArrayComparable;
86  import org.apache.hadoop.hbase.regionserver.HRegion;
87  import org.apache.hadoop.hbase.regionserver.RegionOpeningState;
88  import org.apache.hadoop.hbase.regionserver.wal.HLog;
89  import org.apache.hadoop.hbase.regionserver.wal.HLogKey;
90  import org.apache.hadoop.hbase.util.Bytes;
91  import org.apache.hadoop.io.IntWritable;
92  import org.apache.hadoop.io.MapWritable;
93  import org.apache.hadoop.io.Text;
94  import org.apache.hadoop.io.Writable;
95  import org.apache.hadoop.io.WritableComparator;
96  import org.junit.Assert;
97  import org.junit.experimental.categories.Category;
98  
99  import com.google.common.collect.Lists;
100 import com.google.protobuf.Message;
101 
102 @Category(SmallTests.class)
103 public class TestHbaseObjectWritable extends TestCase {
104 
105   @Override
106   protected void setUp() throws Exception {
107     super.setUp();
108   }
109 
110   @Override
111   protected void tearDown() throws Exception {
112     super.tearDown();
113   }
114 
115   @SuppressWarnings("boxing")
116   public void testReadOldObjectDataInput() throws IOException {
117     Configuration conf = HBaseConfiguration.create();
118     /*
119      * This is the code used to generate byte[] where
120      *  HbaseObjectWritable used byte for code
121      *
122     ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
123     DataOutputStream out = new DataOutputStream(byteStream);
124     HbaseObjectWritable.writeObject(out, bytes, byte[].class, conf);
125     byte[] ba = byteStream.toByteArray();
126     out.close();
127     */
128 
129     /*
130      * byte array generated by the folowing call
131      *  HbaseObjectWritable.writeObject(out, new Text("Old"), Text.class, conf);
132      */
133     byte[] baForText = {13, 13, 3, 79, 108, 100};
134     Text txt = (Text)readByteArray(conf, baForText);
135     Text oldTxt = new Text("Old");
136     assertEquals(txt, oldTxt);
137 
138     final byte A = 'A';
139     byte [] bytes = new byte[1];
140     bytes[0] = A;
141     /*
142      * byte array generated by the folowing call
143      *  HbaseObjectWritable.writeObject(out, bytes, byte[].class, conf);
144      */
145     byte[] baForByteArray = { 11, 1, 65 };
146     byte[] baOut = (byte[])readByteArray(conf, baForByteArray);
147     assertTrue(Bytes.equals(baOut, bytes));
148   }
149 
150   /*
151    * helper method which reads byte array using HbaseObjectWritable.readObject()
152    */
153   private Object readByteArray(final Configuration conf, final byte[] ba)
154   throws IOException {
155     ByteArrayInputStream bais =
156       new ByteArrayInputStream(ba);
157     DataInputStream dis = new DataInputStream(bais);
158     Object product = HbaseObjectWritable.readObject(dis, conf);
159     dis.close();
160     return product;
161   }
162 
163   @SuppressWarnings("boxing")
164   public void testReadObjectDataInputConfiguration() throws IOException {
165     Configuration conf = HBaseConfiguration.create();
166     // Do primitive type
167     final int COUNT = 101;
168     assertTrue(doType(conf, COUNT, int.class).equals(COUNT));
169     // Do array
170     final byte [] testing = "testing".getBytes();
171     byte [] result = (byte [])doType(conf, testing, testing.getClass());
172     assertTrue(WritableComparator.compareBytes(testing, 0, testing.length,
173        result, 0, result.length) == 0);
174     // Do unsupported type.
175     boolean exception = false;
176     try {
177       doType(conf, new Object(), Object.class);
178     } catch (UnsupportedOperationException uoe) {
179       exception = true;
180     }
181     assertTrue(exception);
182     // Try odd types
183     final byte A = 'A';
184     byte [] bytes = new byte[1];
185     bytes[0] = A;
186     Object obj = doType(conf, bytes, byte [].class);
187     assertTrue(((byte [])obj)[0] == A);
188     // Do 'known' Writable type.
189     obj = doType(conf, new Text(""), Text.class);
190     assertTrue(obj instanceof Text);
191     //List.class
192     List<String> list = new ArrayList<String>();
193     list.add("hello");
194     list.add("world");
195     list.add("universe");
196     obj = doType(conf, list, List.class);
197     assertTrue(obj instanceof List);
198     Assert.assertArrayEquals(list.toArray(), ((List)obj).toArray() );
199     //List.class with null values
200     List<String> listWithNulls = new ArrayList<String>();
201     listWithNulls.add("hello");
202     listWithNulls.add("world");
203     listWithNulls.add(null);
204     obj = doType(conf, listWithNulls, List.class);
205     assertTrue(obj instanceof List);
206     Assert.assertArrayEquals(listWithNulls.toArray(), ((List)obj).toArray() );
207     //ArrayList.class
208     ArrayList<String> arr = new ArrayList<String>();
209     arr.add("hello");
210     arr.add("world");
211     arr.add("universe");
212     obj = doType(conf,  arr, ArrayList.class);
213     assertTrue(obj instanceof ArrayList);
214     Assert.assertArrayEquals(list.toArray(), ((ArrayList)obj).toArray() );
215     // Check that filters can be serialized
216     obj = doType(conf, new PrefixFilter(HConstants.EMPTY_BYTE_ARRAY),
217       PrefixFilter.class);
218     assertTrue(obj instanceof PrefixFilter);
219   }
220 
221   public void testCustomWritable() throws Exception {
222     Configuration conf = HBaseConfiguration.create();
223 
224     // test proper serialization of un-encoded custom writables
225     CustomWritable custom = new CustomWritable("test phrase");
226     Object obj = doType(conf, custom, CustomWritable.class);
227     assertTrue(obj instanceof Writable);
228     assertTrue(obj instanceof CustomWritable);
229     assertEquals("test phrase", ((CustomWritable)obj).getValue());
230 
231     // test proper serialization of a custom filter
232     CustomFilter filt = new CustomFilter("mykey");
233     FilterList filtlist = new FilterList(FilterList.Operator.MUST_PASS_ALL);
234     filtlist.addFilter(filt);
235     obj = doType(conf, filtlist, FilterList.class);
236     assertTrue(obj instanceof FilterList);
237     assertNotNull(((FilterList)obj).getFilters());
238     assertEquals(1, ((FilterList)obj).getFilters().size());
239     Filter child = ((FilterList)obj).getFilters().get(0);
240     assertTrue(child instanceof CustomFilter);
241     assertEquals("mykey", ((CustomFilter)child).getKey());
242   }
243 
244   public void testCustomSerializable() throws Exception {
245     Configuration conf = HBaseConfiguration.create();
246 
247     // test proper serialization of un-encoded serialized java objects
248     CustomSerializable custom = new CustomSerializable("test phrase");
249     Object obj = doType(conf, custom, CustomSerializable.class);
250     assertTrue(obj instanceof Serializable);
251     assertTrue(obj instanceof CustomSerializable);
252     assertEquals("test phrase", ((CustomSerializable)obj).getValue());
253   }
254 
255   private Object doType(final Configuration conf, final Object value,
256       final Class<?> clazz)
257   throws IOException {
258     ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
259     DataOutputStream out = new DataOutputStream(byteStream);
260     HbaseObjectWritable.writeObject(out, value, clazz, conf);
261     out.close();
262     ByteArrayInputStream bais =
263       new ByteArrayInputStream(byteStream.toByteArray());
264     DataInputStream dis = new DataInputStream(bais);
265     Object product = HbaseObjectWritable.readObject(dis, conf);
266     dis.close();
267     return product;
268   }
269 
270   public static class A extends IntWritable {
271     public A() {}
272     public A(int a) {super(a);}
273   }
274 
275   public static class B extends A {
276     int b;
277     public B() { }
278     public B(int a, int b) {
279       super(a);
280       this.b = b;
281     }
282     @Override
283     public void write(DataOutput out) throws IOException {
284       super.write(out);
285       out.writeInt(b);
286     }
287 
288     @Override
289     public void readFields(DataInput in) throws IOException {
290       super.readFields(in);
291       this.b = in.readInt();
292     }
293     @Override
294     public boolean equals(Object o) {
295       if (o instanceof B) {
296         return this.get() == ((B) o).get() && this.b == ((B) o).b;
297       }
298       return false;
299     }
300   }
301 
302   /** Tests for serialization of List and Arrays */
303   @SuppressWarnings({ "unchecked", "rawtypes" })
304   public void testPolymorphismInSequences() throws Exception {
305     Configuration conf = HBaseConfiguration.create();
306     Object ret;
307 
308     //test with lists
309     List<A> list = Lists.newArrayList(new A(42), new B(10, 100));
310     ret = doType(conf, list, list.getClass());
311     assertEquals(ret, list);
312 
313     //test with Writable[]
314     Writable[] warr = new Writable[] {new A(42), new B(10, 100)};
315     ret = doType(conf, warr, warr.getClass());
316     Assert.assertArrayEquals((Writable[])ret, warr);
317 
318     //test with arrays
319     A[] arr = new A[] {new A(42), new B(10, 100)};
320     ret = doType(conf, arr, arr.getClass());
321     Assert.assertArrayEquals((A[])ret, arr);
322 
323     //test with double array
324     A[][] darr = new A[][] {new A[] { new A(42), new B(10, 100)}, new A[] {new A(12)}};
325     ret = doType(conf, darr, darr.getClass());
326     Assert.assertArrayEquals((A[][])ret, darr);
327 
328     //test with List of arrays
329     List<A[]> larr = Lists.newArrayList(arr, new A[] {new A(99)});
330     ret = doType(conf, larr, larr.getClass());
331     List<A[]> lret = (List<A[]>) ret;
332     assertEquals(larr.size(), lret.size());
333     for (int i=0; i<lret.size(); i++) {
334       Assert.assertArrayEquals(larr.get(i), lret.get(i));
335     }
336 
337     //test with array of lists
338     List[] alarr = new List[] {Lists.newArrayList(new A(1), new A(2)),
339         Lists.newArrayList(new B(4,5))};
340     ret = doType(conf, alarr, alarr.getClass());
341     List[] alret = (List[]) ret;
342     Assert.assertArrayEquals(alarr, alret);
343 
344     //test with array of Text, note that Text[] is not pre-defined
345     Text[] tarr = new Text[] {new Text("foo"), new Text("bar")};
346     ret = doType(conf, tarr, tarr.getClass());
347     Assert.assertArrayEquals(tarr, (Text[])ret);
348 
349     //test with byte[][]
350     byte[][] barr = new byte[][] {"foo".getBytes(), "baz".getBytes()};
351     ret = doType(conf, barr, barr.getClass());
352     Assert.assertArrayEquals(barr, (byte[][])ret);
353   }
354 
355   public static class CustomSerializable implements Serializable {
356     private static final long serialVersionUID = 1048445561865740632L;
357     private String value = null;
358 
359     public CustomSerializable() {
360     }
361 
362     public CustomSerializable(String value) {
363       this.value = value;
364     }
365 
366     public String getValue() {
367       return value;
368     }
369 
370     public void setValue(String value) {
371       this.value = value;
372     }
373 
374   }
375 
376   public static class CustomWritable implements Writable {
377     private String value = null;
378 
379     public CustomWritable() {
380     }
381 
382     public CustomWritable(String val) {
383       this.value = val;
384     }
385 
386     public String getValue() { return value; }
387 
388     @Override
389     public void write(DataOutput out) throws IOException {
390       Text.writeString(out, this.value);
391     }
392 
393     @Override
394     public void readFields(DataInput in) throws IOException {
395       this.value = Text.readString(in);
396     }
397   }
398 
399   public static class CustomFilter extends FilterBase {
400     private String key = null;
401 
402     public CustomFilter() {
403     }
404 
405     public CustomFilter(String key) {
406       this.key = key;
407     }
408 
409     public String getKey() { return key; }
410 
411     public void write(DataOutput out) throws IOException {
412       Text.writeString(out, this.key);
413     }
414 
415     public void readFields(DataInput in) throws IOException {
416       this.key = Text.readString(in);
417     }
418   }
419 
420   /**
421    * Test case to ensure ordering of CODE_TO_CLASS and CLASS_TO_CODE. In the
422    * past, and item was added in the middle of the static initializer, and that
423    * threw off all of the codes after the addition. This unintentionally broke
424    * the wire protocol for clients. The idea behind this test case is that if
425    * you unintentionally change the order, you will get a test failure. If you
426    * are actually intentionally change the order, just update the test case.
427    * This should be a clue to the reviewer that you are doing something to
428    * change the wire protocol.
429    */
430   public void testGetClassCode() throws IOException{
431     // Primitive types
432     assertEquals(1,HbaseObjectWritable.getClassCode(Boolean.TYPE).intValue());
433     assertEquals(2,HbaseObjectWritable.getClassCode(Byte.TYPE).intValue());
434     assertEquals(3,HbaseObjectWritable.getClassCode(Character.TYPE).intValue());
435     assertEquals(4,HbaseObjectWritable.getClassCode(Short.TYPE).intValue());
436     assertEquals(5,HbaseObjectWritable.getClassCode(Integer.TYPE).intValue());
437     assertEquals(6,HbaseObjectWritable.getClassCode(Long.TYPE).intValue());
438     assertEquals(7,HbaseObjectWritable.getClassCode(Float.TYPE).intValue());
439     assertEquals(8,HbaseObjectWritable.getClassCode(Double.TYPE).intValue());
440     assertEquals(9,HbaseObjectWritable.getClassCode(Void.TYPE).intValue());
441 
442     // Other java types
443     assertEquals(10,HbaseObjectWritable.getClassCode(String.class).intValue());
444     assertEquals(11,HbaseObjectWritable.getClassCode(byte [].class).intValue());
445     assertEquals(12,HbaseObjectWritable.getClassCode(byte [][].class).intValue());
446 
447     // Hadoop types
448     assertEquals(13,HbaseObjectWritable.getClassCode(Text.class).intValue());
449     assertEquals(14,HbaseObjectWritable.getClassCode(Writable.class).intValue());
450     assertEquals(15,HbaseObjectWritable.getClassCode(Writable [].class).intValue());
451     assertEquals(16,HbaseObjectWritable.getClassCode(HbaseMapWritable.class).intValue());
452     // 17 is NullInstance which isn't visible from here
453 
454     // Hbase types
455     assertEquals(18,HbaseObjectWritable.getClassCode(HColumnDescriptor.class).intValue());
456     assertEquals(19,HbaseObjectWritable.getClassCode(HConstants.Modify.class).intValue());
457     // 20 and 21 are place holders for HMsg
458     assertEquals(22,HbaseObjectWritable.getClassCode(HRegion.class).intValue());
459     assertEquals(23,HbaseObjectWritable.getClassCode(HRegion[].class).intValue());
460     assertEquals(24,HbaseObjectWritable.getClassCode(HRegionInfo.class).intValue());
461     assertEquals(25,HbaseObjectWritable.getClassCode(HRegionInfo[].class).intValue());
462     assertEquals(26,HbaseObjectWritable.getClassCode(HServerAddress.class).intValue());
463     assertEquals(27,HbaseObjectWritable.getClassCode(HServerInfo.class).intValue());
464     assertEquals(28,HbaseObjectWritable.getClassCode(HTableDescriptor.class).intValue());
465     assertEquals(29,HbaseObjectWritable.getClassCode(MapWritable.class).intValue());
466 
467     // HBASE-880
468     assertEquals(30,HbaseObjectWritable.getClassCode(ClusterStatus.class).intValue());
469     assertEquals(31,HbaseObjectWritable.getClassCode(Delete.class).intValue());
470     assertEquals(32,HbaseObjectWritable.getClassCode(Get.class).intValue());
471     assertEquals(33,HbaseObjectWritable.getClassCode(KeyValue.class).intValue());
472     assertEquals(34,HbaseObjectWritable.getClassCode(KeyValue[].class).intValue());
473     assertEquals(35,HbaseObjectWritable.getClassCode(Put.class).intValue());
474     assertEquals(36,HbaseObjectWritable.getClassCode(Put[].class).intValue());
475     assertEquals(37,HbaseObjectWritable.getClassCode(Result.class).intValue());
476     assertEquals(38,HbaseObjectWritable.getClassCode(Result[].class).intValue());
477     assertEquals(39,HbaseObjectWritable.getClassCode(Scan.class).intValue());
478 
479     assertEquals(40,HbaseObjectWritable.getClassCode(WhileMatchFilter.class).intValue());
480     assertEquals(41,HbaseObjectWritable.getClassCode(PrefixFilter.class).intValue());
481     assertEquals(42,HbaseObjectWritable.getClassCode(PageFilter.class).intValue());
482     assertEquals(43,HbaseObjectWritable.getClassCode(InclusiveStopFilter.class).intValue());
483     assertEquals(44,HbaseObjectWritable.getClassCode(ColumnCountGetFilter.class).intValue());
484     assertEquals(45,HbaseObjectWritable.getClassCode(SingleColumnValueFilter.class).intValue());
485     assertEquals(46,HbaseObjectWritable.getClassCode(SingleColumnValueExcludeFilter.class).intValue());
486     assertEquals(47,HbaseObjectWritable.getClassCode(BinaryComparator.class).intValue());
487     assertEquals(48,HbaseObjectWritable.getClassCode(BitComparator.class).intValue());
488     assertEquals(49,HbaseObjectWritable.getClassCode(CompareFilter.class).intValue());
489     assertEquals(50,HbaseObjectWritable.getClassCode(RowFilter.class).intValue());
490     assertEquals(51,HbaseObjectWritable.getClassCode(ValueFilter.class).intValue());
491     assertEquals(52,HbaseObjectWritable.getClassCode(QualifierFilter.class).intValue());
492     assertEquals(53,HbaseObjectWritable.getClassCode(SkipFilter.class).intValue());
493     assertEquals(54,HbaseObjectWritable.getClassCode(WritableByteArrayComparable.class).intValue());
494     assertEquals(55,HbaseObjectWritable.getClassCode(FirstKeyOnlyFilter.class).intValue());
495     assertEquals(56,HbaseObjectWritable.getClassCode(DependentColumnFilter.class).intValue());
496 
497     assertEquals(57,HbaseObjectWritable.getClassCode(Delete [].class).intValue());
498 
499     assertEquals(58,HbaseObjectWritable.getClassCode(HLog.Entry.class).intValue());
500     assertEquals(59,HbaseObjectWritable.getClassCode(HLog.Entry[].class).intValue());
501     assertEquals(60,HbaseObjectWritable.getClassCode(HLogKey.class).intValue());
502 
503     assertEquals(61,HbaseObjectWritable.getClassCode(List.class).intValue());
504 
505     assertEquals(62,HbaseObjectWritable.getClassCode(NavigableSet.class).intValue());
506     assertEquals(63,HbaseObjectWritable.getClassCode(ColumnPrefixFilter.class).intValue());
507 
508     // Multi
509     assertEquals(64,HbaseObjectWritable.getClassCode(Row.class).intValue());
510     assertEquals(65,HbaseObjectWritable.getClassCode(Action.class).intValue());
511     assertEquals(66,HbaseObjectWritable.getClassCode(MultiAction.class).intValue());
512     assertEquals(67,HbaseObjectWritable.getClassCode(MultiResponse.class).intValue());
513 
514     // coprocessor execution
515     assertEquals(68,HbaseObjectWritable.getClassCode(Exec.class).intValue());
516     assertEquals(69,HbaseObjectWritable.getClassCode(Increment.class).intValue());
517 
518     assertEquals(70,HbaseObjectWritable.getClassCode(KeyOnlyFilter.class).intValue());
519 
520     // serializable
521     assertEquals(71,HbaseObjectWritable.getClassCode(Serializable.class).intValue());
522     assertEquals(72,HbaseObjectWritable.getClassCode(RandomRowFilter.class).intValue());
523     assertEquals(73,HbaseObjectWritable.getClassCode(CompareOp.class).intValue());
524     assertEquals(74,HbaseObjectWritable.getClassCode(ColumnRangeFilter.class).intValue());
525     assertEquals(75,HbaseObjectWritable.getClassCode(HServerLoad.class).intValue());
526     assertEquals(76,HbaseObjectWritable.getClassCode(RegionOpeningState.class).intValue());
527     assertEquals(77,HbaseObjectWritable.getClassCode(HTableDescriptor[].class).intValue());
528     assertEquals(78,HbaseObjectWritable.getClassCode(Append.class).intValue());
529     assertEquals(79,HbaseObjectWritable.getClassCode(RowMutations.class).intValue());
530     assertEquals(80,HbaseObjectWritable.getClassCode(Message.class).intValue());
531 
532     assertEquals(81,HbaseObjectWritable.getClassCode(Array.class).intValue());
533 
534     // HDP specific
535     assertEquals(-2,HbaseObjectWritable.getClassCode(HServerLoadWithSeqIds.class).intValue());
536   }
537 
538   /**
539    * This test verifies that additional objects have not been added to the end of the list.
540    * If you are legitimately adding objects, this test will need to be updated, but see the
541    * note on the test above.
542    */
543   public void testGetNextObjectCode(){
544     assertEquals(83,HbaseObjectWritable.getNextClassCode());
545   }
546 
547   @org.junit.Rule
548   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
549     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
550 }
551