@Override default VariantStorageEngine getVariantStorageEngine() throws Exception { try (InputStream is = DummyVariantStorageEngine.class.getClassLoader().getResourceAsStream("storage-configuration.yml")) { StorageConfiguration storageConfiguration = StorageConfiguration.load(is); DummyVariantStorageEngine storageManager = new DummyVariantStorageEngine(); storageManager.setConfiguration(storageConfiguration, DummyVariantStorageEngine.STORAGE_ENGINE_ID); return storageManager; } }
@Override public DummyVariantStoragePipeline newStoragePipeline(boolean connected) throws StorageEngineException { return new DummyVariantStoragePipeline(getConfiguration(), STORAGE_ENGINE_ID, getDBAdaptor(), getVariantReaderUtils()); }
@Override public void removeFiles(String study, List<String> files) throws StorageEngineException { List<Integer> fileIds = preRemoveFiles(study, files).getFileIds(); try { Thread.sleep(1); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } postRemoveFiles(study, fileIds, false); }
@Override protected VariantImporter newVariantImporter() throws StorageEngineException { return new VariantImporter(getDBAdaptor()) { @Override public void importData(URI input, VariantMetadata metadata, List<StudyConfiguration> scs) throws StorageEngineException, IOException { } }; }
protected DummyVariantStoragePipeline mockVariantStorageETL(DummyVariantStorageEngine vsm) throws StorageEngineException { DummyVariantStoragePipeline storageETL = spy(vsm.newStoragePipeline(true)); // doReturn(storageETL).when(vsm).newStoragePipeline(anyBoolean()); Mockito.doAnswer(invocation -> { DummyVariantStoragePipeline etl = (DummyVariantStoragePipeline) invocation.callRealMethod(); storageETL.init(etl.getOptions()); return storageETL; }).when(vsm).newStoragePipeline(anyBoolean()); return storageETL; }
@Override public void removeStudy(String studyName) throws StorageEngineException { getStudyConfigurationManager().lockAndUpdate(studyName, studyConfiguration -> { studyConfiguration.getIndexedFiles().clear(); studyConfiguration.getCalculatedStats().clear(); studyConfiguration.getInvalidStats().clear(); studyConfiguration.getCohorts().put(studyConfiguration.getCohortIds().get(StudyEntry.DEFAULT_COHORT), Collections.emptySet()); return studyConfiguration; }); }
@Test public void testCalculateInvalidStats() throws Exception { before(); calculateStats(coh[0]); DummyVariantStorageEngine vsm = mockVariantStorageManager(); String message = "Error"; doThrow(new StorageEngineException(message)).when(vsm).calculateStats(any(), any(List.class), any()); doThrow(new StorageEngineException(message)).when(vsm).calculateStats(any(), any(Map.class), any()); try { calculateStats(coh[1]); fail(); } catch (StorageEngineException e) { assertEquals(message, e.getCause().getMessage()); } Cohort coh1 = catalogManager.getCohortManager().get(studyId, coh[1], null, sessionId).first(); assertEquals(Cohort.CohortStatus.INVALID, coh1.getStatus().getName()); vsm = mockVariantStorageManager(); calculateStats(coh[1]); }
protected DummyVariantDBAdaptor mockVariantDBAdaptor(DummyVariantStorageEngine vsm) throws StorageEngineException { DummyVariantDBAdaptor dbAdaptor = spy(new DummyVariantDBAdaptor("")); doReturn(dbAdaptor).when(vsm).getDBAdaptor(); return dbAdaptor; }
protected DummyVariantStorageEngine mockVariantStorageManager() { DummyVariantStorageEngine vsm = spy(new DummyVariantStorageEngine()); vsm.setConfiguration(opencga.getStorageConfiguration(), DummyVariantStorageEngine.STORAGE_ENGINE_ID, StorageOperation.buildDatabaseName(catalogManager.getConfiguration().getDatabasePrefix(), userId, projectAlias)); StorageEngineFactory.get(opencga.getStorageConfiguration()).registerVariantStorageEngine(vsm); vsm.setConfiguration(opencga.getStorageConfiguration(), DummyVariantStorageEngine.STORAGE_ENGINE_ID, DB_NAME); StorageEngineFactory.get(opencga.getStorageConfiguration()).registerVariantStorageEngine(vsm); return vsm; }