@Test(expectedExceptions = SystemException.class) public void testOnMessageWhenCannotGetObjectShouldThrowSystemException() throws JMSException { indexMessage = new IndexMessage(FILENAME, IndexingType.ADD.getName()); given(objectMessage.getObject()).willThrow(new JMSException("exception")); underTest.onMessage(objectMessage); }
@Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; try { IndexMessage indexMessage = (IndexMessage) objectMessage.getObject(); String fileName = indexMessage.getFileName(); String type = indexMessage.getType(); if (type.equals(IndexingType.ADD.getName())) { luceneEngine.addFileToIndex(fileName); } else if (type.equals(IndexingType.DELETE.getName())) { luceneEngine.deleteFileFromIndex(fileName); } } catch (JMSException e) { throw new SystemException("Message information transfer failed. Reason:" + e.getMessage()); } catch (OutOfMemoryError e) { logger.error("HeapMaxMemory:" + Runtime.getRuntime().maxMemory() + ", HeapTotalMemory:" + Runtime.getRuntime().totalMemory() + ", HeapFreeMemory:" + Runtime.getRuntime().freeMemory() + ", Exception: ", e); shutdown(); } } }
FileIndexerQueueListener implements MessageListener { @Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; try { IndexMessage indexMessage = (IndexMessage) objectMessage.getObject(); String fileName = indexMessage.getFileName(); String type = indexMessage.getType(); if (type.equals(IndexingType.ADD.getName())) { luceneEngine.addFileToIndex(fileName); } else if (type.equals(IndexingType.DELETE.getName())) { luceneEngine.deleteFileFromIndex(fileName); } } catch (JMSException e) { throw new SystemException("Message information transfer failed. Reason:" + e.getMessage()); } catch (OutOfMemoryError e) { logger.error("HeapMaxMemory:" + Runtime.getRuntime().maxMemory() + ", HeapTotalMemory:" + Runtime.getRuntime().totalMemory() + ", HeapFreeMemory:" + Runtime.getRuntime().freeMemory() + ", Exception: ", e); shutdown(); } } } }
FileIndexerQueueListener implements MessageListener { @Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; try { IndexMessage indexMessage = (IndexMessage) objectMessage.getObject(); String fileName = indexMessage.getFileName(); String type = indexMessage.getType(); if (type.equals(IndexingType.ADD.getName())) { luceneEngine.addFileToIndex(fileName); } else if (type.equals(IndexingType.DELETE.getName())) { luceneEngine.deleteFileFromIndex(fileName); } } catch (JMSException e) { throw new SystemException("Message information transfer failed. Reason:" + e.getMessage()); } catch (OutOfMemoryError e) { logger.error("HeapMaxMemory:" + Runtime.getRuntime().maxMemory() + ", HeapTotalMemory:" + Runtime.getRuntime().totalMemory() + ", HeapFreeMemory:" + Runtime.getRuntime().freeMemory() + ", Exception: ", e); shutdown(); } } }  }
FileIndexerQueueListener implements MessageListener { @Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; try { IndexMessage indexMessage = (IndexMessage) objectMessage.getObject(); String fileName = indexMessage.getFileName(); String type = indexMessage.getType(); if (type.equals(IndexingType.ADD.getName())) { luceneEngine.addFileToIndex(fileName); } else if (type.equals(IndexingType.DELETE.getName())) { luceneEngine.deleteFileFromIndex(fileName); } } catch (JMSException e) { throw new SystemException("Message information transfer failed. Reason:" + e.getMessage()); } catch (OutOfMemoryError e) { logger.error("HeapMaxMemory:" + Runtime.getRuntime().maxMemory() + ", HeapTotalMemory:" + Runtime.getRuntime().totalMemory() + ", HeapFreeMemory:" + Runtime.getRuntime().freeMemory() + ", Exception: ", e); shutdown(); } } }  @Override void onMessage(final Message message); }
FileIndexerQueueListener implements MessageListener { @Override public void onMessage(final Message message) { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; try { IndexMessage indexMessage = (IndexMessage) objectMessage.getObject(); String fileName = indexMessage.getFileName(); String type = indexMessage.getType(); if (type.equals(IndexingType.ADD.getName())) { luceneEngine.addFileToIndex(fileName); } else if (type.equals(IndexingType.DELETE.getName())) { luceneEngine.deleteFileFromIndex(fileName); } } catch (JMSException e) { throw new SystemException("Message information transfer failed. Reason:" + e.getMessage()); } catch (OutOfMemoryError e) { logger.error("HeapMaxMemory:" + Runtime.getRuntime().maxMemory() + ", HeapTotalMemory:" + Runtime.getRuntime().totalMemory() + ", HeapFreeMemory:" + Runtime.getRuntime().freeMemory() + ", Exception: ", e); shutdown(); } } }  @Override void onMessage(final Message message);  }