protected final void instantiateDeserializationUtils() { this.deserializedFields1 = new Object[this.serializers.length]; this.deserializedFields2 = new Object[this.serializers.length]; for (int i = 0; i < this.serializers.length; i++) { this.deserializedFields1[i] = this.serializers[i].createInstance(); this.deserializedFields2[i] = this.serializers[i].createInstance(); } }
private Object[] instantiateDeserializationFields() { Object[] newFields = new Object[serializers.length]; for (int i = 0; i < serializers.length; i++) { newFields[i] = serializers[i].createInstance(); } return newFields; }
@Override public T createInstance() { return originalSerializer.createInstance(); }
protected void initializeFields(T t) { for (int i = 0; i < numFields; i++) { if (fields[i] != null) { try { fields[i].set(t, fieldSerializers[i].createInstance()); } catch (IllegalAccessException e) { throw new RuntimeException("Cannot initialize fields.", e); } } } }
@Override public TimerHeapInternalTimer<K, N> createInstance() { return new TimerHeapInternalTimer<>( 0L, keySerializer.createInstance(), namespaceSerializer.createInstance()); }
@Override public void open() throws Exception { super.open(); outTuple = outSerializer.createInstance(); } }
@Override public Either<L, R> createInstance() { // We arbitrarily always create a Right value instance. return Right(rightSerializer.createInstance()); }
@Override public T createInstance() { Object[] fields = new Object[fieldSerializers.length]; for (int index = 0; index < fieldSerializers.length; index++) { fields[index] = fieldSerializers[index].createInstance(); } return createInstance(fields); }
@Override public void writeRecord(T record) throws IOException { T recordCopy = this.typeSerializer.createInstance(); recordCopy = this.typeSerializer.copy(record, recordCopy); this.taskResult.add(recordCopy); }
@Override public StreamRecord<T> createInstance() { return new StreamRecord<T>(typeSerializer.createInstance()); }
@Override public int compareSerialized(final DataInputView firstSource, final DataInputView secondSource) throws IOException { if (this.reference == null) { this.reference = this.serializer.createInstance(); } if (this.tmpReference == null) { this.tmpReference = this.serializer.createInstance(); } this.reference = this.serializer.deserialize(this.reference, firstSource); this.tmpReference = this.serializer.deserialize(this.tmpReference, secondSource); int cmp = this.reference.compareTo(this.tmpReference); return this.ascending ? cmp : -cmp; }
@Override public T createInstance() { try { T t = tupleClass.newInstance(); for (int i = 0; i < arity; i++) { t.setField(fieldSerializers[i].createInstance(), i); } return t; } catch (Exception e) { throw new RuntimeException("Cannot instantiate tuple.", e); } }
@Override public int compareSerialized(DataInputView firstSource, DataInputView secondSource) throws IOException { T first = this.serializer.createInstance(); T second = this.serializer.createInstance(); first = this.serializer.deserialize(first, firstSource); second = this.serializer.deserialize(second, secondSource); return this.compare(first, second); }
@Test public void testInstantiate() { try { TypeSerializer<T> serializer = getSerializer(); if(serializer.getClass().getName().endsWith("KryoSerializer")) { // the kryo serializer will return null. We ignore this test for Kryo. return; } T instance = serializer.createInstance(); assertNotNull("The created instance must not be null.", instance); Class<T> type = getTypeClass(); assertNotNull("The test is corrupt: type class is null.", type); if (!type.isAssignableFrom(instance.getClass())) { fail("Type of the instantiated object is wrong. " + "Expected Type: " + type + " present type " + instance.getClass()); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Override @Test public void testInstantiate() { try { TypeSerializer<T> serializer = getSerializer(); T instance = serializer.createInstance(); assertNotNull("The created instance must not be null.", instance); Class<T> type = getTypeClass(); assertNotNull("The test is corrupt: type class is null.", type); } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Test public void testCopyIntoNewElements() { try { TypeSerializer<T> serializer = getSerializer(); T[] testData = getData(); for (T datum : testData) { T copy = serializer.copy(datum, serializer.createInstance()); checkToString(copy); deepEquals("Copied element is not equal to the original element.", datum, copy); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Test public void testCopyIntoReusedElements() { try { TypeSerializer<T> serializer = getSerializer(); T[] testData = getData(); T target = serializer.createInstance(); for (T datum : testData) { T copy = serializer.copy(datum, target); checkToString(copy); deepEquals("Copied element is not equal to the original element.", datum, copy); target = copy; } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
@Test public void testEqualityWithReference() { try { TypeSerializer<T> serializer = createSerializer(); TypeComparator<T> comparator = getComparator(true); TypeComparator<T> comparator2 = getComparator(true); T[] data = getSortedData(); for (T d : data) { comparator.setReference(d); // Make a copy to compare T copy = serializer.copy(d, serializer.createInstance()); // And then test equalTo and compareToReference method of comparator assertTrue(comparator.equalToReference(d)); comparator2.setReference(copy); assertTrue(comparator.compareToReference(comparator2) == 0); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
protected void writeSortedData(T value, TestOutputView out) throws IOException { TypeSerializer<T> serializer = getSerializer(); // Write data into a outputView serializer.serialize(value, out); // This are the same tests like in the serializer // Just look if the data is really there after serialization, before testing comparator on it TestInputView in = out.getInputView(); assertTrue("No data available during deserialization.", in.available() > 0); T deserialized = serializer.deserialize(serializer.createInstance(), in); deepEquals("Deserialized value is wrong.", value, deserialized); }
@Test public void testSerializeIndividually() { try { TypeSerializer<T> serializer = getSerializer(); T[] testData = getData(); for (T value : testData) { TestOutputView out = new TestOutputView(); serializer.serialize(value, out); TestInputView in = out.getInputView(); assertTrue("No data available during deserialization.", in.available() > 0); T deserialized = serializer.deserialize(serializer.createInstance(), in); checkToString(deserialized); deepEquals("Deserialized value if wrong.", value, deserialized); assertTrue("Trailing data available after deserialization.", in.available() == 0); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }