@Test public void testString() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeString(TestUtil.randomString(random)); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(TestUtil.randomString(random), in.readString()); } @Test public void testSkipNull() throws Exception {
@Test public void testBytes() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeBytes(TestUtil.randomBytes(random)); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(TestUtil.randomBytes(random), in.readBytes(null)); }
public static Random createRandom() { return new Random(getRandomSeed()); }
@Test public void testRandomLength() { long total = 0; int count = 1024 * 1024; int min = Short.MAX_VALUE; int max = 0; Random r = createRandom(); for (int i = 0; i < count; i++) { int length = randomLength(r); if (min > length) min = length; if (max < length) max = length; total += length; } Assert.assertEquals(0, min); Assert.assertTrue(max > 1024 * 32); float average = total / (float)count; Assert.assertTrue(average > 16.0f); Assert.assertTrue(average < 64.0f); }
@Test public void testBoolean() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeValue(random.nextBoolean(), ValueType.BOOLEAN); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(random.nextBoolean(), in.readValue(ValueType.BOOLEAN)); }
Map<Object,Object> map = new HashMap<Object,Object>(length<=0?0:length); for (int i = 0; i < length; i++) { map.put(TestUtil.randomString(random), generate(schema.getValueType(), random, d+1)); random.nextBytes(bytes); return new GenericData.Fixed(schema, bytes); case STRING: return TestUtil.randomString(random); case BYTES: return TestUtil.randomBytes(random); case INT: return random.nextInt(); case LONG: return random.nextLong();
public static String randomString(Random random) { int length = randomLength(random); char[] chars = new char[length]; for (int i = 0; i < length; i++) chars[i] = (char)('a'+random.nextInt('z'-'a')); return new String(chars); }
@Test public void testStdOut() throws Exception { TestUtil.resetRandomSeed(); run(Arrays.asList(new String[] { "-", "--count", COUNT, "--schema-file", SCHEMA_FILE.toString(), "--seed", Long.toString(SEED) })); byte[] file = out.toByteArray(); DataFileStream<Object> reader = new DataFileStream<Object>(new ByteArrayInputStream(file), new GenericDatumReader<>()); Iterator<Object> found = reader.iterator(); for (Object expected : new RandomData(schemaParser.parse(SCHEMA_FILE), Integer.parseInt(COUNT), SEED)) assertEquals(expected, found.next()); reader.close(); } }
@Test public void testFixed32() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeFixed32(random.nextInt()); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(random.nextInt(), in.readFixed32()); }
@Test public void testInts() throws Exception { FILE.delete(); ColumnFileWriter out = new ColumnFileWriter(createFileMeta(), new ColumnMetaData("test", ValueType.INT)); Random random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) out.writeRow(TestUtil.randomLength(random)); out.writeTo(FILE); random = TestUtil.createRandom(); ColumnFileReader in = new ColumnFileReader(FILE); Assert.assertEquals(COUNT, in.getRowCount()); Assert.assertEquals(1, in.getColumnCount()); Iterator<Integer> i = in.getValues("test"); int count = 0; while (i.hasNext()) { Assert.assertEquals(TestUtil.randomLength(random), (int)i.next()); count++; } Assert.assertEquals(COUNT, count); }
public static ByteBuffer randomBytes(Random random) { byte[] bytes = new byte[randomLength(random)]; random.nextBytes(bytes); return ByteBuffer.wrap(bytes); }
@Test public void testStrings() throws Exception { FILE.delete(); ColumnFileWriter out = new ColumnFileWriter(createFileMeta(), new ColumnMetaData("test", ValueType.STRING)); Random random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) out.writeRow(TestUtil.randomString(random)); out.writeTo(FILE); random = TestUtil.createRandom(); ColumnFileReader in = new ColumnFileReader(FILE); Assert.assertEquals(COUNT, in.getRowCount()); Assert.assertEquals(1, in.getColumnCount()); Iterator<String> i = in.getValues("test"); int count = 0; while (i.hasNext()) { Assert.assertEquals(TestUtil.randomString(random), i.next()); count++; } Assert.assertEquals(COUNT, count); }
@Test public void testInt() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeInt(random.nextInt()); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(random.nextInt(), in.readInt()); }
@Test public void testRandomLength() { long total = 0; int count = 1024 * 1024; int min = Short.MAX_VALUE; int max = 0; Random r = createRandom(); for (int i = 0; i < count; i++) { int length = randomLength(r); if (min > length) min = length; if (max < length) max = length; total += length; } Assert.assertEquals(0, min); Assert.assertTrue(max > 1024 * 32); float average = total / (float)count; Assert.assertTrue(average > 16.0f); Assert.assertTrue(average < 64.0f); }
@Test public void testBytes() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeBytes(TestUtil.randomBytes(random)); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(TestUtil.randomBytes(random), in.readBytes(null)); }
public static String randomString(Random random) { int length = randomLength(random); char[] chars = new char[length]; for (int i = 0; i < length; i++) chars[i] = (char)('a'+random.nextInt('z'-'a')); return new String(chars); }
public static Random createRandom() { return new Random(getRandomSeed()); }
.hasIndexValues(true)); Random random = TestUtil.createRandom(); values[i] = TestUtil.randomString(random); Arrays.sort(values);
@Test public void testLong() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeLong(random.nextLong()); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(random.nextLong(), in.readLong()); }
@Test public void testInts() throws Exception { FILE.delete(); ColumnFileWriter out = new ColumnFileWriter(createFileMeta(), new ColumnMetaData("test", ValueType.INT)); Random random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) out.writeRow(TestUtil.randomLength(random)); out.writeTo(FILE); random = TestUtil.createRandom(); ColumnFileReader in = new ColumnFileReader(FILE); Assert.assertEquals(COUNT, in.getRowCount()); Assert.assertEquals(1, in.getColumnCount()); Iterator<Integer> i = in.getValues("test"); int count = 0; while (i.hasNext()) { Assert.assertEquals(TestUtil.randomLength(random), (int)i.next()); count++; } Assert.assertEquals(COUNT, count); }