@Test
  public void testBufferOverflow() {
    BytesColumnVector col = new BytesColumnVector(2048);
    col.reset();
    assertEquals(BytesColumnVector.DEFAULT_BUFFER_SIZE, col.bufferSize());

    // pick a size below 1m so that we use the small buffer;
    final int size = BytesColumnVector.MAX_SIZE_FOR_SMALL_ITEM - 1024;

    // run through once to expand the small value buffer
    for(int row=0; row < col.vector.length; ++row) {
      writeToBytesColumnVector(row, col, size, row);
    }
    // it should have resized a bunch of times
    byte[] sharedBuffer = col.getValPreallocatedBytes();
    assertNotSame(sharedBuffer, col.vector[0]);
    assertSame(sharedBuffer, col.vector[1024]);

    // reset the column, but make sure the buffer isn't reallocated
    col.reset();
    assertEquals(BytesColumnVector.MAX_SIZE_FOR_SHARED_BUFFER, col.bufferSize());

    // fill up the vector now with the large buffer
    for(int row=0; row < col.vector.length; ++row) {
      writeToBytesColumnVector(row, col, size, row);
    }
    assertEquals(BytesColumnVector.MAX_SIZE_FOR_SHARED_BUFFER, col.bufferSize());
    // Now the first 1025 rows should all be the shared buffer,
    // because 1025 * size < MAX_SIZE_FOR_SMALL_BUFFER
    for(int row=0; row < 1025; ++row) {
      assertSame("row " + row, sharedBuffer, col.vector[row]);
      assertEquals("row " + row, row * size, col.start[row]);
      assertEquals("row " + row, size, col.length[row]);
    }
    // the rest should be custom buffers
    for(int row=1025; row < col.vector.length; ++row) {
      assertNotSame("row " + row, sharedBuffer, col.vector[row]);
      assertEquals("row " + row, 0, col.start[row]);
      assertEquals("row " + row, size, col.length[row]);
    }
  }
Test the setVal, setConcat, and StringExpr.padRight methods.
storage-api/src/test/org/apache/hadoop/hive/ql/exec/vector/TestBytesColumnVector.java