public static TypeDescriptor getRuntimeTypeDescriptor () { return new TypeDescriptor(Map.class, new TypeDescriptor(String.class), new TypeDescriptor(List.class, new TypeDescriptor(Pair.class, new TypeDescriptor(String.class), new TypeDescriptor(Long.class)))); }
@Override public TypeDescriptor getAcceptedTypeDescriptor () { return new TypeDescriptor(List.class, new TypeDescriptor(Pair.class, new TypeDescriptor(String.class), new TypeDescriptor(Double.class))); }
/** * Wrap a primitive type in a type descriptor, making sure while doing so that it * actually is a primitive type. */ static <T> TypeDescriptor getPrimitiveTypeDescriptor (Class<? extends T> type) { if (!isValidPrimitive(type)) throw new IllegalArgumentException("Invalid type "+type+ ": Not one of the prescribed primitives allowed."); return new TypeDescriptor(type); }
@Override public TypeDescriptor getAcceptedTypeDescriptor() { return new TypeDescriptor(getAcceptedBinClass()); }
public PairArrayAvroSerializer (Class<? extends S> keyType, Class<? extends T> valueType, CodecFactory compressionCodec) { super(compressionCodec, new TypeDescriptor(Pair.class, PrimitiveAvroSerializer.getPrimitiveTypeDescriptor(keyType), PrimitiveAvroSerializer.getPrimitiveTypeDescriptor(valueType))); _keyType = keyType; _valueType = valueType; _keyToString = (String.class.equals(keyType)); _valueToString = (String.class.equals(valueType)); }
@Test public void testToString () { TypeDescriptor desc = new TypeDescriptor(List.class, new TypeDescriptor(Pair.class, new TypeDescriptor(Double.class), new TypeDescriptor(String.class))); Assert.assertEquals("List<Pair<Double, String>>", desc.toString()); } }
public PairAvroSerializer (Class<? extends S> keyType, Class<? extends T> valueType, CodecFactory compressionCodec) { super(compressionCodec, new TypeDescriptor(Pair.class, PrimitiveAvroSerializer.getPrimitiveTypeDescriptor(keyType), PrimitiveAvroSerializer.getPrimitiveTypeDescriptor(valueType))); _keyType = keyType; _valueType = valueType; _keyToString = (String.class.equals(keyType)); _valueToString = (String.class.equals(valueType)); }
@Test public void testInteger () throws Exception { testRoundTripDense(new TypeDescriptor(Integer.class), EMPTY, 0, 1, 4, 9, 16, 25, 36, 49, 64); testRoundTripSparse(new TypeDescriptor(Integer.class), EMPTY, -1, 0, 1, 4, 9); }
@Test public void testDouble () throws Exception { testRoundTripDense(new TypeDescriptor(Double.class), EMPTY, 0.0, 1.1, 2.4, 3.9, 4.16, 5.25, 6.36, 7.49, 8.64); testRoundTripSparse(new TypeDescriptor(Double.class), EMPTY, -3.5, 1.1, 2.4, 3.9, 4.16); }
@Test public void testFloat () throws Exception { testRoundTripDense(new TypeDescriptor(Float.class), EMPTY, 0.0f, 0.5f, 0.333f, 0.25f, 0.2f, 0.166f, 0.142857f, 0.125f); testRoundTripSparse(new TypeDescriptor(Float.class), EMPTY, -3.5f, 0.0f, 0.5f, 0.333f, 0.25f); }
@Test public void testKryoTileSerialization () throws Exception { serialize(KRYO, SCALAR_DATA, _scalarData, new KryoSerializer<Double>(new TypeDescriptor(Double.class))); }
@Test public void testBoolean () throws Exception { testRoundTripDense(new TypeDescriptor(Boolean.class), EMPTY, true, false, true, true, false, true, false, false, true); testRoundTripSparse(new TypeDescriptor(Boolean.class), EMPTY, true, true, false); }
@Test public void testLong () throws Exception { testRoundTripDense(new TypeDescriptor(Long.class), EMPTY, 0L, 1L, 8L, 27L, 64L, 125L, 216L, 343L, 512L); testRoundTripSparse(new TypeDescriptor(Long.class), EMPTY, -3L, 1L, 8L, 27L, 64L); }
@Test public void testJavaTileSerialization () throws Exception { serialize(JAVA, SCALAR_DATA, _scalarData, new GenericJavaSerializer<Double>(new TypeDescriptor(Double.class))); }
@Test public void testString () throws Exception { testRoundTripDense(new TypeDescriptor(String.class), EMPTY, "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh"); testRoundTripSparse(new TypeDescriptor(String.class), EMPTY, "invalid", "a", "bb", "ccc", "dddd"); }
@Test public void testCompression () throws IOException { TileData<Double> data = new DenseTileData<Double>(new TileIndex(0, 0, 0), 1.1); TileSerializer<Double> serializer = new KryoSerializer<Double>(new TypeDescriptor(Double.class)); ByteArrayOutputStream output = new ByteArrayOutputStream(); serializer.serialize(data, output); output.flush(); output.close(); byte[] buffer = output.toByteArray(); Assert.assertTrue(buffer.length < 256*256); }
@Test public void testKryoDefaultCodecSpecification () throws Exception { TypeDescriptor integerType = new TypeDescriptor(Integer.class); KryoSerializerFactory<Integer> factory = new KryoSerializerFactory<Integer>(null, Arrays.asList("factory"), integerType); factory.readConfiguration(new JSONObject("{}")); TileSerializer<Integer> product = SerializationTypeChecker.checkBinClass(factory.produce(TileSerializer.class), Integer.class, integerType); TileSerializer<Integer> expected = new KryoSerializer<Integer>(integerType, Codec.GZIP); assertSerializersEqual(expected, product, new IntegerSource()); }
@Test public void testKryoGZipSpecification () throws Exception { TypeDescriptor integerType = new TypeDescriptor(Integer.class); KryoSerializerFactory<Integer> factory = new KryoSerializerFactory<Integer>(null, Arrays.asList("factory"), integerType); factory.readConfiguration(new JSONObject("{\"factory\": { \"codec\": \"GZIP\"}}")); TileSerializer<Integer> product = SerializationTypeChecker.checkBinClass(factory.produce(TileSerializer.class), Integer.class, integerType); TileSerializer<Integer> expected = new KryoSerializer<Integer>(integerType, Codec.GZIP); assertSerializersEqual(expected, product, new IntegerSource()); }
@Test public void testKryoBZip2Specification () throws Exception { TypeDescriptor integerType = new TypeDescriptor(Integer.class); KryoSerializerFactory<Integer> factory = new KryoSerializerFactory<Integer>(null, Arrays.asList("factory"), integerType); factory.readConfiguration(new JSONObject("{\"factory\": { \"codec\": \"BZIP\"}}")); TileSerializer<Integer> product = SerializationTypeChecker.checkBinClass(factory.produce(TileSerializer.class), Integer.class, integerType); TileSerializer<Integer> expected = new KryoSerializer<Integer>(integerType, Codec.BZIP); assertSerializersEqual(expected, product, new IntegerSource()); }
@Test public void testKryoDeflateSpecification () throws Exception { TypeDescriptor integerType = new TypeDescriptor(Integer.class); KryoSerializerFactory<Integer> factory = new KryoSerializerFactory<Integer>(null, Arrays.asList("factory"), integerType); factory.readConfiguration(new JSONObject("{\"factory\": { \"codec\": \"DEFLATE\"}}")); TileSerializer<Integer> product = SerializationTypeChecker.checkBinClass(factory.produce(TileSerializer.class), Integer.class, integerType); TileSerializer<Integer> expected = new KryoSerializer<Integer>(integerType, Codec.DEFLATE); assertSerializersEqual(expected, product, new IntegerSource()); }