Queueing1NRelationResultHandlerImpl extends
        QueueingResultHandlerImpl<T> { @Override public void delayCollect() { if (this.prevRow == null) { return; } if (Thread.currentThread().isInterrupted()) { return; } try { Object copy = BeanUtils.cloneBean(this.prevRow); PropertyUtils.copyProperties(this.prevRow, this.prevRow .getClass().newInstance()); if (this.daoCollector != null) { this.daoCollector.addQueue(new DataValueObject(copy, this.dataCount.incrementAndGet())); } } catch (IllegalAccessException e) { throw new SystemException(e); } catch (InstantiationException e) { throw new SystemException(e); } catch (InvocationTargetException e) { throw new SystemException(e); } catch (NoSuchMethodException e) { throw new SystemException(e); } catch (InterruptedException e) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(LogId.TAL041002, Thread.currentThread() .getName()); } Thread.currentThread().interrupt(); } }  @Override void delayCollect();  }
@Test public void testDelayCollect001() { Queueing1NRelationResultHandlerImpl<HogeBean> drh = new Queueing1NRelationResultHandlerImpl<>(); drh.prevRow = null; drh.dataCount = new AtomicLong(0); DaoCollectorStub001 daoCollector = new DaoCollectorStub001(); drh.setDaoCollector(daoCollector); drh.delayCollect(); assertEquals(0L, drh.dataCount.get()); }
@Test public void testDelayCollect002() { Queueing1NRelationResultHandlerImpl<HogeBean> drh = new Queueing1NRelationResultHandlerImpl<>(); HogeBean bean = new HogeBean(); bean.setHoge("hoge1"); drh.prevRow = bean; drh.dataCount = new AtomicLong(0); DaoCollectorStub004 daoCollector = new DaoCollectorStub004(1); daoCollector.setFinish(false); drh.setDaoCollector(daoCollector); drh.delayCollect(); assertEquals(1L, drh.dataCount.get()); DataValueObject obj1 = daoCollector.getQueue().poll(); assertTrue(obj1.getValue() instanceof HogeBean); assertEquals("hoge1", ((HogeBean) obj1.getValue()).getHoge()); assertEquals(1L, obj1.getDataCount()); }
@Test public void testDelayCollect003() { Queueing1NRelationResultHandlerImpl<HogeBean> drh = new Queueing1NRelationResultHandlerImpl<>(); DaoCollectorStub004 daoCollector = new DaoCollectorStub004(5); drh.setDaoCollector(daoCollector); HogeBean hoge1 = new HogeBean(); hoge1.setHoge("hoge1"); HogeBean hoge2 = new HogeBean(); hoge2.setHoge("hoge2"); HogeBean hoge3 = new HogeBean(); hoge3.setHoge("hoge3"); HogeBean hoge4 = new HogeBean(); hoge4.setHoge("hoge4"); DummyResultContext context = new DummyResultContext(); context.setResultObject(hoge1); drh.handleResult(context); context.setResultObject(hoge2); drh.handleResult(context); drh.delayCollect(); context.setResultObject(hoge3); drh.handleResult(context); drh.delayCollect(); context.setResultObject(hoge4); drh.handleResult(context); assertEquals(5L, drh.dataCount.get()); DataValueObject obj1 = daoCollector.getQueue().poll(); assertTrue(obj1.getValue() instanceof HogeBean); assertEquals("hoge1", ((HogeBean) obj1.getValue()).getHoge()); assertEquals(1L, obj1.getDataCount()); DataValueObject obj2 = daoCollector.getQueue().poll(); assertTrue(obj2.getValue() instanceof HogeBean); assertEquals("hoge2", ((HogeBean) obj2.getValue()).getHoge()); assertEquals(2L, obj2.getDataCount()); DataValueObject obj3 = daoCollector.getQueue().poll(); assertTrue(obj3.getValue() instanceof HogeBean); assertNull(((HogeBean) obj3.getValue()).getHoge()); assertEquals(3L, obj3.getDataCount()); DataValueObject obj4 = daoCollector.getQueue().poll(); assertTrue(obj4.getValue() instanceof HogeBean); assertEquals("hoge3", ((HogeBean) obj4.getValue()).getHoge()); assertEquals(4L, obj4.getDataCount()); DataValueObject obj5 = daoCollector.getQueue().poll(); assertTrue(obj5.getValue() instanceof HogeBean); assertNull(((HogeBean) obj5.getValue()).getHoge()); assertEquals(5L, obj5.getDataCount()); assertEquals(0, daoCollector.getQueue().size()); assertEquals("hoge4", ((HogeBean)drh.prevRow).getHoge()); }
@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testDelayCollect004() { Queueing1NRelationResultHandlerImpl drh = new Queueing1NRelationResultHandlerImpl(); drh.prevRow = new TestBean001(); DaoCollector<HogeBean> daoCollector = new DaoCollectorStub002(); ((DaoCollectorStub002) daoCollector).exceptionFlag = false; drh.setDaoCollector(daoCollector); assertNotNull(drh); try { DummyResultContext context = new DummyResultContext(); context.setResultObject(HogeBean.buider().hoge("hoge1").build()); drh.handleResult(context); context.setResultObject(HogeBean.buider().hoge("hoge2").build()); drh.handleResult(context); drh.delayCollect(); fail("失敗"); } catch (SystemException e) { assertNotNull(e); assertEquals(SystemException.class, e.getClass()); assertNotNull(e.getCause()); assertEquals(InvocationTargetException.class, e.getCause() .getClass()); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testDelayCollect005() throws Exception { final Queueing1NRelationResultHandlerImpl drh = new Queueing1NRelationResultHandlerImpl(); final DaoCollectorStub004 daoCollector = new DaoCollectorStub004(2); drh.setDaoCollector(daoCollector); ExecutorService service = Executors.newSingleThreadExecutor(); ErrorFeedBackRunnable runnable = new ErrorFeedBackRunnable() { @Override public void doRun() throws Exception { drh.prevRow = "hoge1"; drh.delayCollect(); drh.prevRow = "hoge2"; Thread.currentThread().interrupt(); drh.delayCollect(); assertTrue(Thread.currentThread().isInterrupted()); } }; service.submit(runnable); runnable.throwErrorOrExceptionIfThrown(); assertEquals(1, daoCollector.getQueue().size()); }