@Test(timeout = 180000) public void testIndexPutWithOffsetAndLength() throws IOException { Path basedir = new Path(DIR + "TestIndexPut"); Configuration conf = TEST_UTIL.getConfiguration(); HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("testIndexPutWithOffsetAndLength")); HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false); HRegion region = HRegion.createHRegion(info, basedir, conf, htd); IndexSpecification spec = new IndexSpecification("index"); spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SpatialPartition(20, 2), ValueType.String, 18); byte[] value1 = "AB---CD---EF---GH---IJ---KL---MN---OP---".getBytes(); Put p = new Put("row".getBytes()); p.add("col".getBytes(), "ql1".getBytes(), value1); Put indexPut = IndexUtils.prepareIndexPut(p, spec, region); byte[] indexRowKey = indexPut.getRow(); byte[] actualResult = new byte[2]; System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length); byte[] expectedResult = new byte[2]; System.arraycopy("IJ".getBytes(), 0, expectedResult, 0, "IJ".getBytes().length); Assert.assertTrue(Bytes.equals(actualResult, expectedResult)); }
@Test(timeout = 180000) public void testIndexPutWithOffsetAndLength() throws IOException { Path basedir = new Path(DIR + "TestIndexPut"); Configuration conf = TEST_UTIL.getConfiguration(); HTableDescriptor htd = new HTableDescriptor("testIndexPutWithOffsetAndLength"); HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false); HRegion region = HRegion.createHRegion(info, basedir, conf, htd); IndexSpecification spec = new IndexSpecification("index"); spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SpatialPartition(20, 2), ValueType.String, 18); byte[] value1 = "AB---CD---EF---GH---IJ---KL---MN---OP---".getBytes(); Put p = new Put("row".getBytes()); p.add("col".getBytes(), "ql1".getBytes(), value1); Put indexPut = IndexUtils.prepareIndexPut(p, spec, region); byte[] indexRowKey = indexPut.getRow(); byte[] actualResult = new byte[2]; System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length); byte[] expectedResult = new byte[2]; System.arraycopy("IJ".getBytes(), 0, expectedResult, 0, "IJ".getBytes().length); Assert.assertTrue(Bytes.equals(actualResult, expectedResult)); }
@Test(timeout = 180000) public void testIndexPutWithOffsetAndLengthWhenPutIsSmallerThanOffset() throws IOException { Path basedir = new Path(DIR + "TestIndexPut"); Configuration conf = TEST_UTIL.getConfiguration(); HTableDescriptor htd = new HTableDescriptor( TableName.valueOf("testIndexPutWithOffsetAndLengthWhenPutIsSmallerThanOffset")); HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false); HRegion region = HRegion.createHRegion(info, basedir, conf, htd); IndexSpecification spec = new IndexSpecification("index"); spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SpatialPartition(20, 2), ValueType.String, 18); byte[] value1 = "AB---CD---EF---GH".getBytes(); Put p = new Put("row".getBytes()); p.add("col".getBytes(), "ql1".getBytes(), value1); Put indexPut = IndexUtils.prepareIndexPut(p, spec, region); byte[] indexRowKey = indexPut.getRow(); byte[] actualResult = new byte[2]; System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length); byte[] expectedResult = new byte[2]; Assert.assertTrue(Bytes.equals(actualResult, expectedResult)); value1 = "AB---CD---EF---GH---I".getBytes(); p = new Put("row".getBytes()); p.add("col".getBytes(), "ql1".getBytes(), value1); indexPut = IndexUtils.prepareIndexPut(p, spec, region); indexRowKey = indexPut.getRow(); actualResult = new byte[2]; System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length); expectedResult = new byte[2]; expectedResult[0] = 'I'; Assert.assertTrue(Bytes.equals(actualResult, expectedResult)); }
@Test(timeout = 180000) public void testColumnQualifierSerialization() throws Exception { ByteArrayOutputStream bos = null; DataOutputStream dos = null; ByteArrayInputStream bis = null; DataInputStream dis = null; try { bos = new ByteArrayOutputStream(); dos = new DataOutputStream(bos); ColumnQualifier cq = new ColumnQualifier("cf", "cq", ValueType.String, 10, new SpatialPartition(0, 5)); cq.write(dos); dos.flush(); byte[] byteArray = bos.toByteArray(); bis = new ByteArrayInputStream(byteArray); dis = new DataInputStream(bis); ColumnQualifier c = new ColumnQualifier(); c.readFields(dis); assertTrue("ColumnQualifier state mismatch.", c.equals(cq)); } finally { if (null != bos) { bos.close(); } if (null != dos) { dos.close(); } if (null != bis) { bis.close(); } if (null != dis) { dis.close(); } } }
@Test(timeout = 180000) public void testIndexPutWithOffsetAndLengthWhenPutIsSmallerThanOffset() throws IOException { Path basedir = new Path(DIR + "TestIndexPut"); Configuration conf = TEST_UTIL.getConfiguration(); HTableDescriptor htd = new HTableDescriptor("testIndexPutWithOffsetAndLengthWhenPutIsSmallerThanOffset"); HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false); HRegion region = HRegion.createHRegion(info, basedir, conf, htd); IndexSpecification spec = new IndexSpecification("index"); spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SpatialPartition(20, 2), ValueType.String, 18); byte[] value1 = "AB---CD---EF---GH".getBytes(); Put p = new Put("row".getBytes()); p.add("col".getBytes(), "ql1".getBytes(), value1); Put indexPut = IndexUtils.prepareIndexPut(p, spec, region); byte[] indexRowKey = indexPut.getRow(); byte[] actualResult = new byte[2]; System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length); byte[] expectedResult = new byte[2]; Assert.assertTrue(Bytes.equals(actualResult, expectedResult)); value1 = "AB---CD---EF---GH---I".getBytes(); p = new Put("row".getBytes()); p.add("col".getBytes(), "ql1".getBytes(), value1); indexPut = IndexUtils.prepareIndexPut(p, spec, region); indexRowKey = indexPut.getRow(); actualResult = new byte[2]; System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length); expectedResult = new byte[2]; expectedResult[0] = 'I'; Assert.assertTrue(Bytes.equals(actualResult, expectedResult)); }