@Test public void testSample() throws IOException { int num = 10000; for (int sampleBufferSize : new int[] {1 << 10, 1 << 20}) { RFile.setSampleBufferSize(sampleBufferSize); for (int modulus : new int[] {19, 103, 1019}) { Hasher dataHasher = Hashing.sha512().newHasher(); List<Entry<Key,Value>> sampleData = new ArrayList<>(); ConfigurationCopy sampleConf = new ConfigurationCopy(conf == null ? DefaultConfiguration.getInstance() : conf); sampleConf.set(Property.TABLE_SAMPLER, RowSampler.class.getName()); sampleConf.set(Property.TABLE_SAMPLER_OPTS + "hasher", "murmur3_32"); sampleConf.set(Property.TABLE_SAMPLER_OPTS + "modulus", modulus + ""); Sampler sampler = SamplerFactory .newSampler(SamplerConfigurationImpl.newSamplerConfig(sampleConf), sampleConf); TestRFile trf = new TestRFile(sampleConf); trf.openWriter(); for (int i = 0; i < num; i++) { add(trf, newKey(i, 0), newValue(i, 0), dataHasher, sampleData, sampler); add(trf, newKey(i, 1), newValue(i, 1), dataHasher, sampleData, sampler); } HashCode expectedDataHash = dataHasher.hash(); trf.closeWriter(); trf.openReader(); FileSKVIterator sample = trf.reader.getSample(SamplerConfigurationImpl.newSamplerConfig(sampleConf)); checkSample(sample, sampleData); assertEquals(expectedDataHash, hash(trf.reader)); SampleIE ie = new SampleIE( SamplerConfigurationImpl.newSamplerConfig(sampleConf).toSamplerConfiguration()); for (int i = 0; i < 3; i++) { trf.reader.closeDeepCopies(); sample = trf.reader.getSample(SamplerConfigurationImpl.newSamplerConfig(sampleConf)); SortedKeyValueIterator<Key,Value> sampleDC1 = sample.deepCopy(ie); SortedKeyValueIterator<Key,Value> sampleDC2 = sample.deepCopy(ie); SortedKeyValueIterator<Key,Value> sampleDC3 = trf.reader.deepCopy(ie); SortedKeyValueIterator<Key,Value> allDC1 = sampleDC1.deepCopy(new SampleIE(null)); SortedKeyValueIterator<Key,Value> allDC2 = sample.deepCopy(new SampleIE(null)); assertEquals(expectedDataHash, hash(allDC1)); assertEquals(expectedDataHash, hash(allDC2)); checkSample(sample, sampleData); checkSample(sampleDC1, sampleData); checkSample(sampleDC2, sampleData); checkSample(sampleDC3, sampleData); } trf.reader.closeDeepCopies(); trf.closeReader(); } } }
@VisibleForTesting public static void setSampleBufferSize(int bufferSize) { sampleBufferSize = bufferSize; }
RFile { @VisibleForTesting public static void setSampleBufferSize(int bufferSize) { sampleBufferSize = bufferSize; } }
RFile { @VisibleForTesting public static void setSampleBufferSize(int bufferSize) { sampleBufferSize = bufferSize; } private  RFile(); }
RFile { @VisibleForTesting public static void setSampleBufferSize(int bufferSize) { sampleBufferSize = bufferSize; } private  RFile(); @VisibleForTesting static void setSampleBufferSize(int bufferSize); }
RFile { @VisibleForTesting public static void setSampleBufferSize(int bufferSize) { sampleBufferSize = bufferSize; } private  RFile(); @VisibleForTesting static void setSampleBufferSize(int bufferSize); static final String EXTENSION; }