@Override protected void put(SystemStreamPartition ssp, IncomingMessageEnvelope envelope) { try { super.put(ssp, envelope); } catch (Exception e) { LOG.error("Exception while putting record. Shutting down SystemStream {}", ssp.getSystemStream(), e); Thread.currentThread().interrupt(); } }
private void offerMessage(SystemStreamPartition systemStreamPartition, IncomingMessageEnvelope envelope) { try { super.put(systemStreamPartition, envelope); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SamzaException("ReaderRunnable interrupted for ssp: " + systemStreamPartition); } }
@Test public void testShouldGetSomeMessages() throws InterruptedException { BlockingEnvelopeMap map = new MockBlockingEnvelopeMap(); map.register(SSP, "0"); map.put(SSP, ENVELOPE); Map<SystemStreamPartition, List<IncomingMessageEnvelope>> envelopes = map.poll(FETCH, 0); assertEquals(1, envelopes.size()); assertEquals(1, envelopes.get(SSP).size()); map.put(SSP, ENVELOPE); map.put(SSP, ENVELOPE); envelopes = map.poll(FETCH, 0); assertEquals(1, envelopes.size()); assertEquals(2, envelopes.get(SSP).size()); // Size info. assertEquals(0, map.getMessagesSizeInQueue(SSP)); }
@Test public void testNoSizeComputation() throws InterruptedException { BlockingEnvelopeMap map = new MockBlockingEnvelopeMap(); map.register(SSP, "0"); map.put(SSP, ENVELOPE); map.put(SSP, ENVELOPE); Map<SystemStreamPartition, List<IncomingMessageEnvelope>> envelopes = map.poll(FETCH, 0); // Size info. assertEquals(0, map.getMessagesSizeInQueue(SSP)); }
@Test public void testSizeComputation() throws InterruptedException { BlockingEnvelopeMap map = new MockBlockingEnvelopeMap(true); map.register(SSP, "0"); map.put(SSP, ENVELOPE_WITH_SIZE); map.put(SSP, ENVELOPE_WITH_SIZE); // Size info. assertEquals(200, map.getMessagesSizeInQueue(SSP)); Map<SystemStreamPartition, List<IncomingMessageEnvelope>> envelopes = map.poll(FETCH, 0); assertEquals(0, map.getMessagesSizeInQueue(SSP)); }