@Test public void testWriteAfterRemoving() throws Exception { data.copyFrom(new BytesArray("a")); data.copyFrom(new BytesArray("bb")); data.copyFrom(new BytesArray("ccc")); data.remove(1); ByteArrayOutputStream out = new ByteArrayOutputStream(); data.writeTo(out); assertEquals("accc", out.toString()); }
data.copyFrom(payload);
@Test public void testRemoveSize() throws Exception { assertEquals(0, data.length()); data.copyFrom(new BytesArray("a")); data.copyFrom(new BytesArray("bb")); data.copyFrom(new BytesArray("ccc")); data.copyFrom(new BytesArray("dddd")); assertEquals(10, data.length()); data.remove(1); assertEquals(8, data.length()); data.remove(1); assertEquals(5, data.length()); }
@Test public void testAddArraySize() throws Exception { assertEquals(0, data.length()); data.copyFrom(new BytesArray("one")); assertEquals(3, data.length()); data.copyFrom(new BytesArray("two")); assertEquals(6, data.length()); data.copyFrom(new BytesArray("three")); assertEquals(11, data.length()); }
@Test public void testPopData() throws Exception { assertEquals(0, data.length()); data.copyFrom(new BytesArray("a")); data.copyFrom(new BytesArray("bb")); data.copyFrom(new BytesArray("ccc")); data.copyFrom(new BytesArray("dddd")); assertEquals(10, data.length()); BytesArray entry = data.pop(); assertEquals(9, data.length()); assertEquals(1, entry.length()); entry = data.pop(); assertEquals(7, data.length()); assertEquals(2, entry.length()); } }
data.copyFrom(newEntry);
@Test public void testAddRefSize() throws Exception { BytesRef ref = new BytesRef(); ref.add(new BytesArray("one")); ref.add(new BytesArray("three")); data.copyFrom(ref); assertEquals(8, data.length()); }
data.copyFrom(payload);
data.copyFrom(payload);
data.copyFrom(payload);
private void doWriteToIndex(BytesRef payload) { // check space first // ba is the backing array for data if (payload.length() > ba.available()) { if (autoFlush) { flush(); } else { throw new EsHadoopIllegalStateException( String.format("Auto-flush disabled and bulk buffer full; disable manual flush or increase capacity [current size %s]; bailing out", ba.capacity())); } } data.copyFrom(payload); payload.reset(); dataEntries++; if (bufferEntriesThreshold > 0 && dataEntries >= bufferEntriesThreshold) { if (autoFlush) { flush(); } else { // handle the corner case of manual flush that occurs only after the buffer is completely full (think size of 1) if (dataEntries > bufferEntriesThreshold) { throw new EsHadoopIllegalStateException( String.format( "Auto-flush disabled and maximum number of entries surpassed; disable manual flush or increase capacity [current size %s]; bailing out", bufferEntriesThreshold)); } } } }
data.copyFrom(newEntry);
data.copyFrom(newEntry);
data.copyFrom(newEntry);