/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
BytesRef result = new BytesRef();
@Test public void testWriteBulkEntryWithHandlersThatCorrectsData() { BytesRef response = new BytesRef(); response.add("abcdefg".getBytes()); BulkCommand command = Mockito.mock(BulkCommand.class); Mockito.when(command.write(1)).thenThrow(new EsHadoopIllegalStateException("Things broke")); Mockito.when(command.write(10)).thenReturn(response); Settings settings = new TestSettings(); settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLERS, "fix"); settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLER+".fix", CorrectingHandler.class.getName()); BulkEntryWriter bulkEntryWriter = new BulkEntryWriter(settings, command); BytesRef value = bulkEntryWriter.writeBulkEntry(1); Assert.assertNotNull("Skipped values should be null", value); Assert.assertEquals(7, response.length()); Assert.assertArrayEquals("abcdefg".getBytes(), response.toString().getBytes()); }
@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()); }
@Test public void testAddAndReset() throws Exception { BytesArrayPool pool = new BytesArrayPool(); pool.get().bytes("Test"); pool.get().bytes("Data"); pool.get().bytes("Rules"); BytesRef ref = new BytesRef(); assertEquals(13, pool.length()); ref.add(pool); assertEquals("TestDataRules", ref.toString()); BytesRef ref2 = new BytesRef(); pool.reset(); pool.get().bytes("New"); pool.get().bytes("Info"); assertEquals(7, pool.length()); ref2.add(pool); assertEquals("NewInfo", ref2.toString()); } }
private void processData(BulkProcessor processor) { BytesRef data = new BytesRef(); data.add(renderEntry("A")); processor.add(data); data.reset(); data.add(renderEntry("B")); processor.add(data); data.reset(); data.add(renderEntry("C")); processor.add(data); data.reset(); data.add(renderEntry("D")); processor.add(data); data.reset(); data.add(renderEntry("E")); processor.add(data); data.reset(); }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { writeInitialized = true; autoFlush = !settings.getBatchFlushManual(); ba.bytes(new byte[settings.getBatchSizeInBytes()], 0); trivialBytesRef = new BytesRef(); bufferEntriesThreshold = settings.getBatchSizeInEntries(); requiresRefreshAfterBulk = settings.getBatchRefreshAfterWrite(); this.command = BulkCommands.create(settings, metaExtractor); } }
BytesRef result = new BytesRef();
BytesRef result = new BytesRef();
BytesRef result = new BytesRef();