StoreMetadataValueService extends DuplicateMetadataValueService { @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { String value = msg.getMetadataValue(getMetadataKey()); Args.notBlank(value, "metadataKey"); previousValuesStore.add(value); while (previousValuesStore.size() > getNumberOfPreviousValuesToStore()) { previousValuesStore.remove(0); } storePreviouslyReceivedValues(); } catch (Exception e) { throw ExceptionHelper.wrapServiceException(e); } } StoreMetadataValueService(); @Override void doService(AdaptrisMessage msg); int getNumberOfPreviousValuesToStore(); void setNumberOfPreviousValuesToStore(int i);  }
@Test public void testService() throws Exception { StoreMetadataValueService service = createService(); StoreMetadataValueService service2 = createService(); try { LifecycleHelper.initAndStart(service); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); assertEquals(0, service.storeSize()); msg.addMetadata(DEFAULT_METADATA_KEY, "123"); service.doService(msg); assertEquals(1, service.storeSize()); service.doService(msg); assertEquals(2, service.storeSize()); msg.addMetadata(DEFAULT_METADATA_KEY, "456"); service.doService(msg); assertEquals(3, service.storeSize()); LifecycleHelper.initAndStart(service2); assertEquals(3, service2.storeSize()); } finally { LifecycleHelper.stopAndClose(service); LifecycleHelper.stopAndClose(service2); } }