@Test public void testSpc674RaceCondition() throws Exception { final String foreignSource = "spc674"; System.err.println("=== create a requisition like the ReST service does, import it immediately ==="); final Requisition initial = new Requisition(foreignSource); initial.putNode(createNode("1")); initial.updateDateStamp(); m_pending.save(initial); final URL node1Snapshot = createSnapshot(foreignSource); Resource resource = new UrlResource(node1Snapshot); doImport(resource); Thread.sleep(5); List<String> files = getImports(foreignSource); assertEquals(1, files.size()); System.err.println("=== create another snapshot, but don't import it yet ==="); initial.putNode(createNode("2")); initial.updateDateStamp(); m_pending.save(initial); final URL node2Snapshot = createSnapshot(foreignSource); Thread.sleep(5); files = getImports(foreignSource); assertEquals(3, files.size()); System.err.println("=== create yet another snapshot, and don't import it yet ==="); initial.putNode(createNode("3")); initial.updateDateStamp(); m_pending.save(initial); final URL node3Snapshot = createSnapshot(foreignSource); Thread.sleep(5); files = getImports(foreignSource); assertEquals(4, files.size()); System.err.println("=== import of the second file finishes ==="); doImport(new UrlResource(node2Snapshot)); Thread.sleep(5); files = getImports(foreignSource); assertEquals(2, files.size()); System.err.println("=== fourth node is sent to the ReST interface ==="); final Requisition currentPending = RequisitionFileUtils.getLatestPendingOrSnapshotRequisition(m_pending, foreignSource); assertNotNull(currentPending); assertEquals(initial.getDate(), currentPending.getDate()); currentPending.putNode(createNode("4")); currentPending.updateDateStamp(); m_pending.save(currentPending); final URL node4Snapshot = createSnapshot(foreignSource); Thread.sleep(5); files = getImports(foreignSource); assertEquals(4, files.size()); System.err.println("=== import of the third file finishes ==="); doImport(new UrlResource(node3Snapshot)); Thread.sleep(5); files = getImports(foreignSource); assertEquals(2, files.size()); System.err.println("=== import of the fourth file finishes ==="); doImport(new UrlResource(node4Snapshot)); Thread.sleep(5); files = getImports(foreignSource); assertEquals(1, files.size()); }
public synchronized void save(ForeignSource foreignSource) throws ForeignSourceRepositoryException { m_pendingForeignSourceRepository.delete(foreignSource); m_deployedForeignSourceRepository.save(foreignSource); }
FusedForeignSourceRepository extends AbstractForeignSourceRepository implements ForeignSourceRepository, InitializingBean { public synchronized void save(ForeignSource foreignSource) throws ForeignSourceRepositoryException { m_pendingForeignSourceRepository.delete(foreignSource); m_deployedForeignSourceRepository.save(foreignSource); } }
FusedForeignSourceRepository extends AbstractForeignSourceRepository implements ForeignSourceRepository, InitializingBean { public synchronized void save(ForeignSource foreignSource) throws ForeignSourceRepositoryException { m_pendingForeignSourceRepository.delete(foreignSource); m_deployedForeignSourceRepository.save(foreignSource); }  }
FusedForeignSourceRepository extends AbstractForeignSourceRepository implements ForeignSourceRepository, InitializingBean { public synchronized void save(ForeignSource foreignSource) throws ForeignSourceRepositoryException { m_pendingForeignSourceRepository.delete(foreignSource); m_deployedForeignSourceRepository.save(foreignSource); }  @Override void afterPropertiesSet(); ForeignSourceRepository getPendingForeignSourceRepository(); void setPendingForeignSourceRepository(final ForeignSourceRepository fsr); ForeignSourceRepository getDeployedForeignSourceRepository(); void setDeployedForeignSourceRepository(final ForeignSourceRepository fsr); Set<String> getActiveForeignSourceNames(); @Override synchronized Requisition importResourceRequisition(final Resource resource); synchronized void delete(ForeignSource foreignSource); synchronized void delete(Requisition requisition); ForeignSource getForeignSource(String foreignSourceName); int getForeignSourceCount(); Set<ForeignSource> getForeignSources(); Requisition getRequisition(String foreignSourceName); Requisition getRequisition(ForeignSource foreignSource); @Override Date getRequisitionDate(String foreignSource); @Override URL getRequisitionURL(String foreignSource); Set<Requisition> getRequisitions(); synchronized void save(ForeignSource foreignSource); synchronized void save(final Requisition requisition); @Override void flush(); }
FusedForeignSourceRepository extends AbstractForeignSourceRepository implements ForeignSourceRepository, InitializingBean { public synchronized void save(ForeignSource foreignSource) throws ForeignSourceRepositoryException { m_pendingForeignSourceRepository.delete(foreignSource); m_deployedForeignSourceRepository.save(foreignSource); }  @Override void afterPropertiesSet(); ForeignSourceRepository getPendingForeignSourceRepository(); void setPendingForeignSourceRepository(final ForeignSourceRepository fsr); ForeignSourceRepository getDeployedForeignSourceRepository(); void setDeployedForeignSourceRepository(final ForeignSourceRepository fsr); Set<String> getActiveForeignSourceNames(); @Override synchronized Requisition importResourceRequisition(final Resource resource); synchronized void delete(ForeignSource foreignSource); synchronized void delete(Requisition requisition); ForeignSource getForeignSource(String foreignSourceName); int getForeignSourceCount(); Set<ForeignSource> getForeignSources(); Requisition getRequisition(String foreignSourceName); Requisition getRequisition(ForeignSource foreignSource); @Override Date getRequisitionDate(String foreignSource); @Override URL getRequisitionURL(String foreignSource); Set<Requisition> getRequisitions(); synchronized void save(ForeignSource foreignSource); synchronized void save(final Requisition requisition); @Override void flush();  }