DbSecurityMaster extends AbstractDocumentDbMaster<SecurityDocument> implements SecurityMaster { @Override public SecurityDocument get(final UniqueId uniqueId) { final SecurityDocument doc = doGet(uniqueId, new SecurityDocumentExtractor(), "Security"); loadDetail(getDetailProvider(), Collections.singletonList(doc)); return doc; } DbSecurityMaster(final DbConnector dbConnector); @Override void registerMetrics(MetricRegistry summaryRegistry, MetricRegistry detailedRegistry, String namePrefix); SecurityMasterDetailProvider getDetailProvider(); void setDetailProvider(SecurityMasterDetailProvider detailProvider); @Override SecurityMetaDataResult metaData(SecurityMetaDataRequest request); @Override SecuritySearchResult search(final SecuritySearchRequest request); @Override SecurityDocument get(final UniqueId uniqueId); @Override SecurityDocument get(final ObjectIdentifiable objectId, final VersionCorrection versionCorrection); @Override SecurityHistoryResult history(final SecurityHistoryRequest request); static final String IDENTIFIER_SCHEME_DEFAULT; }
@Test public void test_equity() throws Exception { EquitySecurity sec = new EquitySecurity("London", "LON", "OpenGamma Ltd", Currency.GBP); sec.setName("OpenGamma"); sec.setGicsCode(GICSCode.of("20102010")); sec.setShortName("OG"); sec.setExternalIdBundle(ExternalIdBundle.of("Test", "OG")); SecurityDocument addDoc = new SecurityDocument(sec); SecurityDocument added = _secMaster.add(addDoc); SecurityDocument loaded = _secMaster.get(added.getUniqueId()); assertEquals(added, loaded); }
@Test public void test_equity_withAttribute() throws Exception { EquitySecurity sec = new EquitySecurity("London", "LON", "OpenGamma Ltd", Currency.GBP); sec.setName("OpenGamma"); sec.setGicsCode(GICSCode.of("20102010")); sec.setShortName("OG"); sec.setExternalIdBundle(ExternalIdBundle.of("Test", "OG")); sec.addAttribute("ATTR_KEY", "ATTR_VALUE"); SecurityDocument addDoc = new SecurityDocument(sec); SecurityDocument added = _secMaster.add(addDoc); SecurityDocument loaded = _secMaster.get(added.getUniqueId()); assertEquals(added, loaded); }
@Test public void test_equity_with_attribute_permission() throws Exception { EquitySecurity sec = new EquitySecurity("London", "LON", "OpenGamma Ltd", Currency.GBP); sec.setName("OpenGamma"); sec.setGicsCode(GICSCode.of("20102010")); sec.setShortName("OG"); sec.setExternalIdBundle(ExternalIdBundle.of("Test", "OG")); sec.addAttribute("1", "One"); sec.addAttribute("2", "Two"); sec.getRequiredPermissions().add("A"); sec.getRequiredPermissions().add("B"); SecurityDocument addDoc = new SecurityDocument(sec); SecurityDocument added = _secMaster.add(addDoc); assertNotNull(added); assertNotNull(added.getSecurity()); assertNotNull(added.getSecurity().getUniqueId()); final UniqueId addedUniqueId = UniqueId.of(added.getSecurity().getUniqueId().getScheme(), added.getSecurity().getUniqueId().getValue(), added.getSecurity().getUniqueId().getVersion()); added.getSecurity().setUniqueId(null); assertEquals(sec, added.getSecurity()); SecurityDocument loaded = _secMaster.get(addedUniqueId); assertEquals(addedUniqueId, loaded.getUniqueId()); added.getSecurity().setUniqueId(addedUniqueId); assertEquals(added, loaded); }
@Test(enabled = false) public void test_concurrentModification() { final AtomicReference<Throwable> exceptionOccurred = new AtomicReference<Throwable>(); Runnable task = new Runnable() { @Override public void run() { try { test_equity(); } catch (Throwable th) { exceptionOccurred.compareAndSet(null, th); } } }; ExecutorService executor = Executors.newFixedThreadPool(5); LinkedList<Future<?>> futures = new LinkedList<Future<?>>(); for (int i = 0; i < 10; i++) { futures.add(executor.submit(task)); } while (!futures.isEmpty()) { Future<?> future = futures.poll(); try { future.get(); } catch (Throwable t) { s_logger.error("Exception waiting for task to complete", t); } } assertEquals(null, exceptionOccurred.get()); }