PageRenderTime 54ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/hcatalog/storage-handlers/hbase/src/test/org/apache/hcatalog/hbase/snapshot/TestThriftSerialization.java

http://github.com/apache/hive
Java | 85 lines | 53 code | 14 blank | 18 comment | 7 complexity | 0ace57bc159f058d80ab48b5af440e92 MD5 | raw file
Possible License(s): Apache-2.0
  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,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.apache.hcatalog.hbase.snapshot;
  20. import static org.junit.Assert.assertTrue;
  21. import java.io.IOException;
  22. import java.util.ArrayList;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. import org.apache.hcatalog.hbase.snapshot.transaction.thrift.StoreFamilyRevision;
  26. import org.apache.hcatalog.hbase.snapshot.transaction.thrift.StoreFamilyRevisionList;
  27. import org.junit.Test;
  28. public class TestThriftSerialization {
  29. @Test
  30. public void testLightWeightTransaction() {
  31. StoreFamilyRevision trxn = new StoreFamilyRevision(0, 1000);
  32. try {
  33. byte[] data = ZKUtil.serialize(trxn);
  34. StoreFamilyRevision newWtx = new StoreFamilyRevision();
  35. ZKUtil.deserialize(newWtx, data);
  36. assertTrue(newWtx.getRevision() == trxn.getRevision());
  37. assertTrue(newWtx.getTimestamp() == trxn.getTimestamp());
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42. @Test
  43. public void testWriteTransactionList() {
  44. List<StoreFamilyRevision> txnList = new ArrayList<StoreFamilyRevision>();
  45. long version;
  46. long timestamp;
  47. for (int i = 0; i < 10; i++) {
  48. version = i;
  49. timestamp = 1000 + i;
  50. StoreFamilyRevision wtx = new StoreFamilyRevision(version, timestamp);
  51. txnList.add(wtx);
  52. }
  53. StoreFamilyRevisionList wList = new StoreFamilyRevisionList(txnList);
  54. try {
  55. byte[] data = ZKUtil.serialize(wList);
  56. StoreFamilyRevisionList newList = new StoreFamilyRevisionList();
  57. ZKUtil.deserialize(newList, data);
  58. assertTrue(newList.getRevisionListSize() == wList.getRevisionListSize());
  59. Iterator<StoreFamilyRevision> itr = newList.getRevisionListIterator();
  60. int i = 0;
  61. while (itr.hasNext()) {
  62. StoreFamilyRevision txn = itr.next();
  63. assertTrue(txn.getRevision() == i);
  64. assertTrue(txn.getTimestamp() == (i + 1000));
  65. i++;
  66. }
  67. } catch (IOException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71. }