@Test public void shouldSearchForExistingGroupBeforeUpdating() throws Exception { FlwGroup toBeUpdatedGroup = new FlwGroupBuilder() .groupId("5ba9a0928dde95d187544babf6c0ad24") .name("afrisis team 1") .domain("care-bihar") .awcCode("001") .caseSharing(true) .reporting(true) .build(); FlwGroup notToBeUpdatedGroup = flwGroupWithNameAndId("5ba9a0928dde95d187544babf6c0af36", "ashok team 1"); template.saveOrUpdateAll(Arrays.asList(toBeUpdatedGroup, notToBeUpdatedGroup)); FlwGroup updatedGroup = updatedGroup(); careService.saveOrUpdateAllByExternalPrimaryKey(FlwGroup.class, Arrays.asList(updatedGroup)); FlwGroup loadedFlwGroup = template.load(FlwGroup.class, toBeUpdatedGroup.getId()); FlwGroup unchangedFlwGroup = template.load(FlwGroup.class, notToBeUpdatedGroup.getId()); assertReflectionEqualsWithIgnore( updatedGroup(), loadedFlwGroup, new String[] {"id", "creationTime", "lastModifiedTime"}); assertDateIgnoringSeconds(new Date(), loadedFlwGroup.getCreationTime()); assertDateIgnoringSeconds(new Date(), loadedFlwGroup.getLastModifiedTime()); assertEquals("ashok team 1", unchangedFlwGroup.getName()); }
@Test public void testLoadSIF() throws Exception { String filepath = TestUtils.DATA_DIR + "sample/BRCA_sif.txt"; List<String> expectedAttributeNames = Arrays.asList( "TCGA_EXPERIMENT", "TCGA_BATCH", "TUMOR_NORMAL", "BIRDSEED_GENDER", "LEVEL2_NOISE", "LEVEL3_SEGMENT_COUNT", "PURITY PLOIDY", "DELTA", "CANCER_DNA_FRACTION", "SUBCLONAL_GENOME_FRACTION"); tstLoadFi(filepath, 0, false); // Sample information file, shouldn't have tracks. Set<String> attrNames = new HashSet<String>(AttributeManager.getInstance().getAttributeNames()); assertTrue( attrNames.size() >= expectedAttributeNames.size()); // Can be larger because of default attributes for (String name : expectedAttributeNames) { assertTrue(expectedAttributeNames.contains(name)); } }
@Test public void shouldSearchExistingFlwsAndUpdateFlw() { Flw toBeUpdatedFlw = flw( "5ba9a0928dde95d187544babf6c0ad24", "FirstName1", flwGroupWithNameAndId("64a9a0928dde95d187544babf6c0ad38", "oldGroupName")); Flw notToBeUpdateFlw = flw("5ba9a0928dde95d187544babf6c0ad25", "FirstName2", new FlwGroup()); template.saveOrUpdateAll(Arrays.asList(toBeUpdatedFlw, notToBeUpdateFlw)); Flw newFlw = flw( "5ba9a0928dde95d187544babf6c0ad24", "FirstName3", flwGroupWithNameAndId("38a9a0928dde95d187544babf6c0ad64", "newGroupName")); ArrayList<Flw> flwsToUpdate = new ArrayList<>(); flwsToUpdate.add(newFlw); careService.saveOrUpdateAllByExternalPrimaryKey(Flw.class, flwsToUpdate); Flw updatedFlw = template.load(Flw.class, toBeUpdatedFlw.getId()); assertReflectionEqualsWithIgnore( newFlw, updatedFlw, new String[] {"id", "creationTime", "lastModifiedTime"}); assertDateIgnoringSeconds(new Date(), updatedFlw.getCreationTime()); assertDateIgnoringSeconds(new Date(), updatedFlw.getLastModifiedTime()); Flw unchangedFlw = template.load(Flw.class, notToBeUpdateFlw.getId()); assertEquals("FirstName2", unchangedFlw.getFirstName()); }
@BeforeClass public static void prepare() throws Exception // NOPMD { Registry.activateStandaloneMode(); Utilities.setJUnitTenant(); LOG.debug("Preparing..."); final ApplicationContext appCtx = Registry.getGlobalApplicationContext(); assertTrue( "Application context of type " + appCtx.getClass() + " is not a subclass of " + ConfigurableApplicationContext.class, appCtx instanceof ConfigurableApplicationContext); final ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) appCtx; final ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory(); assertTrue( "Bean Factory of type " + beanFactory.getClass() + " is not of type " + BeanDefinitionRegistry.class, beanFactory instanceof BeanDefinitionRegistry); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory); xmlReader.setDocumentReaderClass(ScopeTenantIgnoreDocReader.class); xmlReader.loadBeanDefinitions( new ClassPathResource( "/merchandisefulfilmentprocess/test/merchandisefulfilmentprocess-spring-test.xml")); xmlReader.loadBeanDefinitions( new ClassPathResource( "/merchandisefulfilmentprocess/test/merchandisefulfilmentprocess-spring-test-fraudcheck.xml")); xmlReader.loadBeanDefinitions( new ClassPathResource( "/merchandisefulfilmentprocess/test/process/order-process-spring.xml")); modelService = (ModelService) getBean("modelService"); processService = (DefaultBusinessProcessService) getBean("businessProcessService"); definitonFactory = processService.getProcessDefinitionFactory(); LOG.warn("Prepare Process Definition factory..."); definitonFactory.add( "classpath:/merchandisefulfilmentprocess/test/process/payment-process.xml"); // setup command factory to mock final DefaultCommandFactoryRegistryImpl commandFactoryReg = appCtx.getBean(DefaultCommandFactoryRegistryImpl.class); commandFactoryReg.setCommandFactoryList( Arrays.asList((CommandFactory) appCtx.getBean("mockupCommandFactory"))); taskServiceStub = appCtx.getBean(TaskServiceStub.class); productService = appCtx.getBean("defaultProductService", DefaultProductService.class); cartService = appCtx.getBean("defaultCartService", DefaultCartService.class); userService = appCtx.getBean("defaultUserService", DefaultUserService.class); }
@Test public void shouldCreateNewFlw() { Flw newFlw = flw( "5ba9a0928dde95d187544babf6c0ad24", "FirstName1", flwGroupWithNameAndId("64a9a0928dde95d187544babf6c0ad38", "oldGroupName")); careService.saveOrUpdateAllByExternalPrimaryKey(Flw.class, Arrays.asList(newFlw)); List<Flw> flwsFromDb = template.loadAll(Flw.class); assertEquals(1, flwsFromDb.size()); assertReflectionContains(newFlw, flwsFromDb, new String[] {"id"}); }
public static void assertColumns(ColumnFamily cf, String... columnNames) { Collection<IColumn> columns = cf == null ? new TreeSet<IColumn>() : cf.getSortedColumns(); List<String> L = new ArrayList<String>(); for (IColumn column : columns) { L.add(new String(column.name())); } assert Arrays.equals(L.toArray(new String[columns.size()]), columnNames) : "Columns [" + ((cf == null) ? "" : cf.getComparator().getColumnsString(columns)) + "]" + " is not expected [" + StringUtils.join(columnNames, ",") + "]"; }
/** * Test loading segmented data file from a sql database, using a profile * * @throws Exception */ @Test public void testLoadSegProfile() throws Exception { String path = TestUtils.DATA_DIR + "sql/seg_canFam2_profile.dbxml"; int expectedTracks = 6; List<Track> tracks = trackLoader.load(new ResourceLocator(path), genome); assertEquals(expectedTracks, tracks.size()); Set<String> expSampleIds = new HashSet<String>( Arrays.asList("0123-A", "0123-B-1", "0123-C-1", "0123-C-2", "0123-C-3")); Set<String> actSampleIds = new HashSet<String>(5); for (Track track : tracks) { if (track instanceof DataSourceTrack) { actSampleIds.add(track.getName()); } } assertEquals(expSampleIds, actSampleIds); }
@Test public void shouldSaveNewGroup() throws Exception { FlwGroup newGroup = new FlwGroupBuilder() .groupId("5ba9a0928dde95d187544babf6c0ad24") .name("amir team 1") .domain("care-mp") .awcCode("007") .caseSharing(true) .reporting(true) .build(); careService.saveOrUpdateAllByExternalPrimaryKey(FlwGroup.class, Arrays.asList(newGroup)); List<FlwGroup> flwGroupsFromDb = template.loadAll(FlwGroup.class); assertEquals(1, flwGroupsFromDb.size()); assertReflectionContains(newGroup, flwGroupsFromDb, new String[] {"id"}); }
/** * Test loading sample information file from a sql database, using a profile * * @throws Exception */ @Test public void testLoadSampleInfoProfile() throws Exception { AttributeManager.getInstance().clearAllAttributes(); String path = TestUtils.DATA_DIR + "sql/sampleinfo_brca_sif_profile.dbxml"; int expectedTracks = 0; List<Track> tracks = trackLoader.load(new ResourceLocator(path), genome); assertEquals(expectedTracks, tracks.size()); String[] attrNames = "TCGA_EXPERIMENT TCGA_BATCH TUMOR_NORMAL BIRDSEED_GENDER LEVEL2_NOISE LEVEL3_SEGMENT_COUNT PURITY PLOIDY DELTA CANCER_DNA_FRACTION SUBCLONAL_GENOME_FRACTION" .split("\\s+"); Set<String> expAttrNames = new HashSet<String>(Arrays.asList(attrNames)); List<String> actAttrNames = AttributeManager.getInstance().getAttributeNames(); actAttrNames.remove("NAME"); actAttrNames.remove("DATA TYPE"); actAttrNames.remove("DATA FILE"); assertEquals(actAttrNames.size(), expAttrNames.size()); for (String attrName : actAttrNames) { assertTrue(expAttrNames.contains(attrName)); } }
@Test public void downloadAsInputStream() throws IOException { InputStream byteStream = object.downloadObjectAsInputStream(); assertTrue(Arrays.equals(bytes, IOUtils.toByteArray(byteStream))); }
@Test public void downloadAsByteArray() { byte[] result = object.downloadObject(); assertTrue(Arrays.equals(bytes, result)); }
/** Read a contiguous set of registers. */ @Override public TimestampedData readTimeStamped(int ireg, int creg) { try { synchronized (this.concurrentClientLock) { synchronized (this.callbackLock) { // Wait until the write cache isn't busy. This honors the visibility semantic // we intend to portray, namely that issuing a read after a write has been // issued will see the state AFTER the write has had a chance to take effect. while (this.writeCacheStatus != WRITE_CACHE_STATUS.IDLE) { this.callbackLock.wait(); } // If there's no read window given or what's there either can't service any // more reads or it doesn't contain the required registers, auto-make a new window. if (this.readWindow == null || !this.readWindow.isOkToRead() || !this.readWindow.contains(ireg, creg)) { // If we can re-use the window that was there before that will help increase // the chance that we don't need to take the time to switch the controller to // read mode (with a different window) and thus can respond faster. if (this.readWindow != null && this.readWindow.contains(ireg, creg)) { setReadWindow(this.readWindow); } else { // Make a one-shot that just covers the data we need right now setReadWindow(new ReadWindow(ireg, creg, READ_MODE.ONLY_ONCE)); } } // We can only fetch registers that lie within the current register window. // This actually should never trigger now, as the above should ALWAYS auto-adjust // the window if necessary, but we have it here still as a check. if (!this.readWindow.contains(ireg, creg)) { throw new IllegalArgumentException( String.format( "read request (%d,%d) outside of read window (%d, %d)", ireg, creg, this.readWindow.getIregFirst(), this.readWindow.getCreg())); } // Wait until the read cache is valid while (this.readWindowChanged || !this.readCacheStatus.isValid()) { this.callbackLock.wait(); } // Extract the data and return! this.readCacheLock.lockInterruptibly(); try { assertTrue(!BuildConfig.DEBUG || this.readWindowActuallyRead.contains(this.readWindow)); // The data of interest is somewhere in the read window, but not necessarily at the // start. int ibFirst = ireg - this.readWindowActuallyRead.getIregFirst() + dibCacheOverhead; TimestampedData result = new TimestampedData(); result.data = Arrays.copyOfRange(this.readCache, ibFirst, ibFirst + creg); result.nanoTime = this.nanoTimeReadCacheValid; return result; } finally { this.readCacheLock.unlock(); // If that was a one-time read, invalidate the data so we won't read it again a second // time. // Note that this is the only place outside of the callback that we ever update // readCacheStatus or writeCacheStatus if (this.readCacheStatus == READ_CACHE_STATUS.VALID_ONLYONCE) this.readCacheStatus = READ_CACHE_STATUS.IDLE; } } } } catch (InterruptedException e) { Util.handleCapturedInterrupt(e); // Can't return (no data to return!) so we must throw throw SwerveRuntimeException.wrap(e); } }
private void validateSliceLarge(ColumnFamilyStore cfStore) throws IOException { String key = "row3"; ColumnFamily cf; cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), "col1000".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 3); assertColumns(cf, "col1000", "col1001", "col1002"); assertEquals(new String(cf.getColumn("col1000".getBytes()).value()), "v1000"); assertEquals(new String(cf.getColumn("col1001".getBytes()).value()), "v1001"); assertEquals(new String(cf.getColumn("col1002".getBytes()).value()), "v1002"); cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), "col1195".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 3); assertColumns(cf, "col1195", "col1196", "col1197"); assertEquals(new String(cf.getColumn("col1195".getBytes()).value()), "v1195"); assertEquals(new String(cf.getColumn("col1196".getBytes()).value()), "v1196"); assertEquals(new String(cf.getColumn("col1197".getBytes()).value()), "v1197"); cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), "col1996".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 1000); IColumn[] columns = cf.getSortedColumns().toArray(new IColumn[0]); for (int i = 1000; i < 1996; i++) { String expectedName = "col" + i; IColumn column = columns[i - 1000]; assert Arrays.equals(column.name(), expectedName.getBytes()) : cfStore.getComparator().getString(column.name()) + " is not " + expectedName; assert Arrays.equals(column.value(), ("v" + i).getBytes()); } cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), "col1990".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 3); assertColumns(cf, "col1990", "col1991", "col1992"); assertEquals(new String(cf.getColumn("col1990".getBytes()).value()), "v1990"); assertEquals(new String(cf.getColumn("col1991".getBytes()).value()), "v1991"); assertEquals(new String(cf.getColumn("col1992".getBytes()).value()), "v1992"); cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY, true, 3); assertColumns(cf, "col1997", "col1998", "col1999"); assertEquals(new String(cf.getColumn("col1999".getBytes()).value()), "v1999"); assertEquals(new String(cf.getColumn("col1998".getBytes()).value()), "v1998"); assertEquals(new String(cf.getColumn("col1997".getBytes()).value()), "v1997"); cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), "col9000".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, true, 3); assertColumns(cf, "col1997", "col1998", "col1999"); cf = cfStore.getColumnFamily( key, new QueryPath("Standard1"), "col9000".getBytes(), ArrayUtils.EMPTY_BYTE_ARRAY, false, 3); assertColumns(cf); }