You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by am...@apache.org on 2020/11/11 20:18:00 UTC
[ignite] branch ignite-13618 created (now 9390f24)
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a change to branch ignite-13618
in repository https://gitbox.apache.org/repos/asf/ignite.git.
at 9390f24 WIP. Add Reflection-based serializer.
This branch includes the following new commits:
new 6562730 Add checkstyle plugin. Add license check plugin.
new 71a9439 Add JUnit 5 support.
new 9390f24 WIP. Add Reflection-based serializer.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[ignite] 03/03: WIP. Add Reflection-based serializer.
Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-13618
in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 9390f2416a90fb8d5859560dadcc1ccfad777757
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Wed Nov 11 22:57:49 2020 +0300
WIP. Add Reflection-based serializer.
---
.../schema/marshaller/BaseTypeMarshaller.java | 63 ++++
.../internal/schema/marshaller/BinaryMode.java | 90 +++++
.../schema/marshaller/ClassMarshaller.java | 91 +++++
.../internal/schema/marshaller/FieldAccessor.java | 398 +++++++++++++++++++++
.../internal/schema/marshaller/JavaSerializer.java | 304 ++++++++++++++++
.../internal/schema/marshaller/Marshaller.java | 64 ++++
.../internal/schema/marshaller/ObjectFactory.java | 70 ++++
.../schema/marshaller/SerializationException.java | 28 ++
8 files changed, 1108 insertions(+)
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/BaseTypeMarshaller.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/BaseTypeMarshaller.java
new file mode 100644
index 0000000..7b9d0f4
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/BaseTypeMarshaller.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import java.util.Objects;
+import org.apache.ignite.internal.schema.Tuple;
+import org.apache.ignite.internal.schema.TupleAssembler;
+
+/**
+ * (De)serializer handler for object of base types.
+ */
+class BaseTypeMarshaller implements Marshaller {
+ /** Write mode. */
+ private final BinaryMode mode;
+
+ /**
+ * Constructor.
+ *
+ * @param mode Binary mode.
+ */
+ public BaseTypeMarshaller(BinaryMode mode) {
+ this.mode = Objects.requireNonNull(mode);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int nonNullVarLenCols(Object obj) {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object value(Object obj, int colIdx) {
+ assert colIdx == 0 : "No columns expected for native types.";
+
+ return obj;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object readObject(Tuple reader) {
+ return JavaSerializer.readRefValue(reader, 0, mode);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObject(Object val, TupleAssembler writer) {
+ Objects.requireNonNull(val, "Null values are not supported."); //TODO: Add 'tombstones' (null-values) support.
+
+ JavaSerializer.writeRefObject(val, writer, mode);
+ }
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/BinaryMode.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/BinaryMode.java
new file mode 100644
index 0000000..b24c495
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/BinaryMode.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import org.apache.ignite.internal.schema.NativeTypeSpec;
+
+/**
+ * Various read/write modes for binary objects that maps Java types to binary types.
+ */
+enum BinaryMode {
+ /** Primitive byte. */
+ P_BYTE(NativeTypeSpec.BYTE),
+
+ /** Primitive short. */
+ P_SHORT(NativeTypeSpec.SHORT),
+
+ /** Primitive int. */
+ P_INT(NativeTypeSpec.INTEGER),
+
+ /** Primitive long. */
+ P_LONG(NativeTypeSpec.LONG),
+
+ /** Primitive float. */
+ P_FLOAT(NativeTypeSpec.FLOAT),
+
+ /** Primitive int. */
+ P_DOUBLE(NativeTypeSpec.DOUBLE),
+
+ /** */
+ BYTE(NativeTypeSpec.BYTE),
+
+ /** */
+ SHORT(NativeTypeSpec.SHORT),
+
+ /** */
+ INT(NativeTypeSpec.INTEGER),
+
+ /** */
+ LONG(NativeTypeSpec.LONG),
+
+ /** */
+ FLOAT(NativeTypeSpec.FLOAT),
+
+ /** */
+ DOUBLE(NativeTypeSpec.DOUBLE),
+
+ /** */
+ STRING(NativeTypeSpec.STRING),
+
+ /** */
+ UUID(NativeTypeSpec.UUID),
+
+ /** */
+ BYTE_ARR(NativeTypeSpec.BYTES),
+
+ /** */
+ BITSET(NativeTypeSpec.BITMASK);
+
+ /** Natove type spec. */
+ private final NativeTypeSpec typeSpec;
+
+ /**
+ * @param typeSpec Native type spec.
+ */
+ BinaryMode(NativeTypeSpec typeSpec) {
+ this.typeSpec = typeSpec;
+ }
+
+ /**
+ * @return Native type spec.
+ */
+ public NativeTypeSpec typeSpec() {
+ return typeSpec;
+ }
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/ClassMarshaller.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/ClassMarshaller.java
new file mode 100644
index 0000000..3bc1d76
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/ClassMarshaller.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import org.apache.ignite.internal.schema.Columns;
+import org.apache.ignite.internal.schema.Tuple;
+import org.apache.ignite.internal.schema.TupleAssembler;
+import org.jetbrains.annotations.Unmodifiable;
+
+/**
+ * General purpose (de)serializer handler for objects of complex types.
+ */
+public class ClassMarshaller<T> implements Marshaller {
+ /** Mapped columns. */
+ private final Columns cols;
+
+ /**
+ * Field accessors for mapped columns.
+ * Array has same size and order as columns.
+ */
+ private final FieldAccessor[] fieldAccessors;
+
+ /** Object factory for class. */
+ private final ObjectFactory<T> factory;
+
+ /**
+ * Constructor.
+ *
+ * @param cols Mapped columns.
+ * @param factory Object factory.
+ * @param fieldAccessors Object field accessors for mapped columns.
+ */
+ @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+ public ClassMarshaller(Columns cols, ObjectFactory<T> factory, FieldAccessor[] fieldAccessors) {
+ this.cols = cols;
+ this.fieldAccessors = fieldAccessors;
+ this.factory = factory;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int nonNullVarLenCols(Object obj) throws SerializationException {
+ if (obj == null)
+ return 0;
+
+ int cnt = 0;
+
+ for (int fldIdx = cols.firstVarlengthColumn(); fldIdx < cols.length(); fldIdx++) {
+ if (fieldAccessors[fldIdx].value(obj) == null)
+ cnt++;
+ }
+
+ return cnt;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object value(Object obj, int fldIdx) throws SerializationException {
+ return fieldAccessors[fldIdx].value(obj);
+ }
+
+ /** {@inheritDoc} */
+ @Override public Object readObject(Tuple reader) throws SerializationException {
+ final T obj = factory.newInstance();
+
+ for (int fldIdx = 0; fldIdx < fieldAccessors.length; fldIdx++)
+ fieldAccessors[fldIdx].read(obj, reader);
+
+ return obj;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeObject(Object obj, TupleAssembler writer) throws SerializationException {
+ for (int fldIdx = 0; fldIdx < fieldAccessors.length; fldIdx++) {
+ fieldAccessors[fldIdx].write(obj, writer);
+ }
+ }
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java
new file mode 100644
index 0000000..45f79c7
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/FieldAccessor.java
@@ -0,0 +1,398 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import java.lang.reflect.Field;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.Tuple;
+import org.apache.ignite.internal.schema.TupleAssembler;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Field accessor to speedup access.
+ */
+//TODO: Rewrite to direct field access via Unsafe to bypass security checks.
+//TODO: Extract interface, move to java-8 profile and add implementation based on VarHandle for java9+.
+public abstract class FieldAccessor {
+ /**
+ * TODO: implement sesitive information filtering.
+ *
+ * @return {@code False} if sensitive information exoising is prohibited, {@code false} otherwise.
+ */
+ private static boolean includeSensitive() {
+ return true;
+ }
+
+ /** Field name */
+ protected final Field field;
+
+ /** Mode. */
+ protected final BinaryMode mode;
+
+ /** Column index. */
+ protected final int colIdx;
+
+ /**
+ * Create accessor for the field.
+ *
+ * @param field Field.
+ * @param col Mapped column.
+ * @param colIdx Column index.
+ * @return Accessor.
+ */
+ //TODO: Extract a provider for this factory-method.
+ public static FieldAccessor create(Field field, Column col, int colIdx) {
+ if (field.getType().isPrimitive() && col.nullable()) //TODO: convert to assert?
+ throw new IllegalArgumentException("Failed to map non-nullable field to nullable column [name=" + field.getName() + ']');
+
+ BinaryMode mode = JavaSerializer.mode(field.getType());
+
+ switch (mode) {
+ case P_BYTE:
+ return new BytePrimitiveAccessor(field, colIdx);
+
+ case P_SHORT:
+ return new ShortPrimitiveAccessor(field, colIdx);
+
+ case P_INT:
+ return new IntPrimitiveAccessor(field, colIdx);
+
+ case P_LONG:
+ return new LongPrimitiveAccessor(field, colIdx);
+
+ case P_FLOAT:
+ return new FloatPrimitiveAccessor(field, colIdx);
+
+ case P_DOUBLE:
+ return new DoublePrimitiveAccessor(field, colIdx);
+
+ case BYTE:
+ case SHORT:
+ case INT:
+ case LONG:
+ case FLOAT:
+ case DOUBLE:
+ case STRING:
+ case UUID:
+ case BYTE_ARR:
+ case BITSET:
+ return new ReferenceFieldAccessor(field, colIdx, mode);
+
+ default:
+ assert false : "Invalid mode " + mode;
+ }
+
+ throw new IllegalArgumentException("Failed to create accessor for field [name=" + field.getName() + ']');
+ }
+
+ /**
+ * Protected constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ * @param mode Binary mode;
+ */
+ protected FieldAccessor(Field field, int colIdx, BinaryMode mode) {
+ assert field != null;
+ assert colIdx >= 0;
+ assert mode != null;
+
+ this.field = field;
+ this.colIdx = colIdx;
+ this.mode = mode;
+
+ field.setAccessible(true);
+ }
+
+ /**
+ * Get binary read/write mode.
+ *
+ * @return Binary mode.
+ */
+ public BinaryMode mode() {
+ return mode;
+ }
+
+ /**
+ * Write object field value to tuple.
+ *
+ * @param obj Source object.
+ * @param writer Tuple writer.
+ * @throws SerializationException If failed.
+ */
+ public void write(Object obj, TupleAssembler writer) throws SerializationException {
+ try {
+ write0(obj, writer);
+ }
+ catch (Exception ex) {
+ if (includeSensitive())
+ throw new SerializationException("Failed to write field [name=" + field.getName() + ']', ex);
+ else
+ throw new SerializationException("Failed to write field [id=" + colIdx + ']', ex);
+ }
+ }
+
+ /**
+ * Write object field value to tuple.
+ *
+ * @param obj Source object.
+ * @param writer Tuple writer.
+ * @throws IllegalAccessException If failed.
+ */
+ protected abstract void write0(Object obj, TupleAssembler writer) throws IllegalAccessException;
+
+ /**
+ * Reads value fom tuple to object field.
+ *
+ * @param obj Target object.
+ * @param reader Tuple reader.
+ * @throws SerializationException If failed.
+ */
+ public void read(Object obj, Tuple reader) throws SerializationException {
+ try {
+ read0(obj, reader);
+ }
+ catch (Exception ex) {
+ if (includeSensitive())
+ throw new SerializationException("Failed to read field [name=" + field.getName() + ']', ex);
+ else
+ throw new SerializationException("Failed to read field [id=" + colIdx + ']', ex);
+ }
+ }
+
+ /**
+ * Reads value fom tuple to object field.
+ *
+ * @param obj Target object.
+ * @param reader Tuple reader.
+ * @throws IllegalAccessException If failed.
+ */
+ protected abstract void read0(Object obj, Tuple reader) throws IllegalAccessException;
+
+ /**
+ * Reads object field value.
+ *
+ * @param obj Object.
+ * @return Field value of given object.
+ * @throws SerializationException If failed.
+ */
+ @Nullable Object value(Object obj) throws SerializationException {
+ try {
+ return field.get(obj);
+ }
+ catch (IllegalAccessException ex) {
+ if (includeSensitive())
+ throw new SerializationException("Failed to read field [name=" + field.getName() + ']', ex);
+ else
+ throw new SerializationException("Failed to read field [id=" + colIdx + ']', ex);
+ }
+ }
+
+ /**
+ * Accessor for field of primitive {@code byte} type.
+ */
+ private static class BytePrimitiveAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ */
+ public BytePrimitiveAccessor(Field field, int colIdx) {
+ super(field, colIdx, BinaryMode.P_BYTE);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ writer.appendByte(field.getByte(obj));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ field.setByte(obj, reader.byteValue(colIdx));
+ }
+ }
+
+ /**
+ * Accessor for field of primitive {@code short} type.
+ */
+ private static class ShortPrimitiveAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ */
+ public ShortPrimitiveAccessor(Field field, int colIdx) {
+ super(field, colIdx, BinaryMode.P_SHORT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ writer.appendShort(field.getShort(obj));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ field.setShort(obj, reader.shortValue(colIdx));
+ }
+ }
+
+ /**
+ * Accessor for field of primitive {@code int} type.
+ */
+ private static class IntPrimitiveAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ */
+ public IntPrimitiveAccessor(Field field, int colIdx) {
+ super(field, colIdx, BinaryMode.P_INT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ writer.appendInt(field.getInt(obj));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ field.setInt(obj, reader.intValue(colIdx));
+ }
+ }
+
+ /**
+ * Accessor for field of primitive {@code long} type.
+ */
+ private static class LongPrimitiveAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ */
+ public LongPrimitiveAccessor(Field field, int colIdx) {
+ super(field, colIdx, BinaryMode.P_LONG);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ writer.appendLong(field.getLong(obj));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ field.setLong(obj, reader.longValue(colIdx));
+ }
+ }
+
+ /**
+ * Accessor for field of primitive {@code float} type.
+ */
+ private static class FloatPrimitiveAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ */
+ public FloatPrimitiveAccessor(Field field, int colIdx) {
+ super(field, colIdx, BinaryMode.P_FLOAT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ writer.appendFloat(field.getFloat(obj));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ field.setFloat(obj, reader.floatValue(colIdx));
+ }
+ }
+
+ /**
+ * Accessor for field of primitive {@code double} type.
+ */
+ private static class DoublePrimitiveAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ */
+ public DoublePrimitiveAccessor(Field field, int colIdx) {
+ super(field, colIdx, BinaryMode.P_DOUBLE);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ writer.appendDouble(field.getDouble(obj));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ field.setDouble(obj, reader.doubleValue(colIdx));
+ }
+ }
+
+ /**
+ * Accessor for field of reference type.
+ */
+ private static class ReferenceFieldAccessor extends FieldAccessor {
+ /**
+ * Constructor.
+ *
+ * @param field Field.
+ * @param colIdx Column index.
+ * @param mode Binary mode.
+ */
+ ReferenceFieldAccessor(Field field, int colIdx, BinaryMode mode) {
+ super(field, colIdx, mode);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void write0(Object obj, TupleAssembler writer) throws IllegalAccessException {
+ assert obj != null;
+ assert writer != null;
+
+ Object val;
+
+ val = field.get(obj);
+
+ if (val == null) {
+ writer.appendNull();
+
+ return;
+ }
+
+ JavaSerializer.writeRefObject(val, writer, mode);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void read0(Object obj, Tuple reader) throws IllegalAccessException {
+ Object val = JavaSerializer.readRefValue(reader, colIdx, mode);
+
+ assert !field.getType().isPrimitive();
+
+ field.set(obj, val);
+ }
+ }
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java
new file mode 100644
index 0000000..ebecee9
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/JavaSerializer.java
@@ -0,0 +1,304 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import java.util.BitSet;
+import java.util.UUID;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.SchemaDescriptor;
+import org.apache.ignite.internal.schema.Tuple;
+import org.apache.ignite.internal.schema.TupleAssembler;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Cache objects (de)serializer.
+ * <p>
+ * TODO: Extract interface.
+ */
+public class JavaSerializer {
+
+ /**
+ * Gets binary read/write mode for given class.
+ *
+ * @param cls Type.
+ * @return Binary mode.
+ */
+ public static BinaryMode mode(Class<?> cls) {
+ assert cls != null;
+
+ // Primitives.
+ if (cls == byte.class)
+ return BinaryMode.P_BYTE;
+ else if (cls == short.class)
+ return BinaryMode.P_SHORT;
+ else if (cls == int.class)
+ return BinaryMode.P_INT;
+ else if (cls == long.class)
+ return BinaryMode.P_LONG;
+ else if (cls == float.class)
+ return BinaryMode.P_FLOAT;
+ else if (cls == double.class)
+ return BinaryMode.P_DOUBLE;
+
+ // Boxed primitives.
+ else if (cls == Byte.class)
+ return BinaryMode.BYTE;
+ else if (cls == Short.class)
+ return BinaryMode.SHORT;
+ else if (cls == Integer.class)
+ return BinaryMode.INT;
+ else if (cls == Long.class)
+ return BinaryMode.LONG;
+ else if (cls == Float.class)
+ return BinaryMode.FLOAT;
+ else if (cls == Double.class)
+ return BinaryMode.DOUBLE;
+
+ // Other types
+ else if (cls == byte[].class)
+ return BinaryMode.BYTE_ARR;
+ else if (cls == String.class)
+ return BinaryMode.STRING;
+ else if (cls == UUID.class)
+ return BinaryMode.UUID;
+ else if (cls == BitSet.class)
+ return BinaryMode.BITSET;
+
+ return null;
+ }
+
+ /**
+ * Reads value object from tuple.
+ *
+ * @param reader Reader.
+ * @param colIdx Column index.
+ * @param mode Binary read mode.
+ * @return Read value object.
+ */
+ static Object readRefValue(Tuple reader, int colIdx, BinaryMode mode) {
+ assert reader != null;
+ assert colIdx >= 0;
+
+ Object val = null;
+
+ switch (mode) {
+ case BYTE:
+ val = reader.byteValueBoxed(colIdx);
+
+ break;
+
+ case SHORT:
+ val = reader.shortValueBoxed(colIdx);
+
+ break;
+
+ case INT:
+ val = reader.intValueBoxed(colIdx);
+
+ break;
+
+ case LONG:
+ val = reader.longValueBoxed(colIdx);
+
+ break;
+
+ case FLOAT:
+ val = reader.floatValueBoxed(colIdx);
+
+ break;
+
+ case DOUBLE:
+ val = reader.doubleValueBoxed(colIdx);
+
+ break;
+
+ case STRING:
+ val = reader.stringValue(colIdx);
+
+ break;
+
+ case UUID:
+ val = reader.uuidValue(colIdx);
+
+ break;
+
+ case BYTE_ARR:
+ val = reader.bytesValue(colIdx);
+
+ break;
+
+ case BITSET:
+ val = reader.bitmaskValue(colIdx);
+
+ break;
+
+ default:
+ assert false : "Invalid mode: " + mode;
+ }
+
+ return val;
+ }
+
+ /**
+ * Writes reference value to tuple.
+ *
+ * @param val Value object.
+ * @param writer Writer.
+ * @param mode Write binary mode.
+ */
+ static void writeRefObject(Object val, TupleAssembler writer, BinaryMode mode) {
+ assert writer != null;
+
+ if (val == null) {
+ writer.appendNull();
+
+ return;
+ }
+
+ switch (mode) {
+ case BYTE:
+ writer.appendByte((Byte)val);
+
+ break;
+
+ case SHORT:
+ writer.appendShort((Short)val);
+
+ break;
+
+ case INT:
+ writer.appendInt((Integer)val);
+
+ break;
+
+ case LONG:
+ writer.appendLong((Long)val);
+
+ break;
+
+ case FLOAT:
+ writer.appendFloat((Float)val);
+
+ break;
+
+ case DOUBLE:
+ writer.appendDouble((Double)val);
+
+ break;
+
+ case STRING:
+ writer.appendString((String)val);
+
+ break;
+
+ case UUID:
+ writer.appendUuid((UUID)val);
+
+ break;
+
+ case BYTE_ARR:
+ writer.appendBytes((byte[])val);
+
+ break;
+
+ case BITSET:
+ writer.appendBitmask((BitSet)val);
+
+ break;
+
+ default:
+ assert false : "Invalid mode: " + mode;
+ }
+ }
+
+ /** Schema. */
+ private final SchemaDescriptor schema;
+
+ private final Class<?> keyClass;
+ private final Class<?> valClass;
+
+ /** Key marshaller. */
+ private final Marshaller keyMarsh;
+
+ /** Value marshaller. */
+ private final Marshaller valMarsh;
+
+ /**
+ * Constructor.
+ *
+ * @param schema Schema.
+ * @param keyClass Key type.
+ * @param valClass Value type.
+ */
+ public JavaSerializer(SchemaDescriptor schema, Class<?> keyClass, Class<?> valClass) {
+ this.schema = schema;
+ this.keyClass = keyClass;
+ this.valClass = valClass;
+
+ keyMarsh = createMarshaller(schema, keyClass);
+ valMarsh = createMarshaller(schema, valClass);
+ }
+
+ /**
+ * Creates marshaller for class.
+ *
+ * @param schema Schema.
+ * @param aClass Type.
+ * @return Marshaller.
+ */
+ @NotNull private <T> Marshaller createMarshaller(SchemaDescriptor schema, Class<T> aClass) {
+ final BinaryMode mode = mode(aClass);
+
+ if (mode != null) {
+ final Column col = schema.keyColumns().column(0);
+
+ assert mode.typeSpec() == col.type().spec() : "Target type is not compatible.";
+ assert aClass.isPrimitive() && col.nullable() : "Non-nullable types are not allowed.";
+
+ return new BaseTypeMarshaller(mode);
+ }
+
+ // TODO: Build accessors
+
+ return new ClassMarshaller<>(schema.keyColumns(), ObjectFactory.classFactory(aClass), null);
+ }
+
+ /**
+ * Writes key-value pair to tuple.
+ *
+ * @param key Key object.
+ * @param val Value object.
+ * @return Serialized key-value pair.
+ */
+ public byte[] serialize(Object key, Object val) throws SerializationException {
+ assert keyClass.isInstance(key);
+ assert val == null || valClass.isInstance(val);
+
+ int size = 0;
+
+ int nonNullVarLenKeyCols = keyMarsh.nonNullVarLenCols(key);
+ int nonNullVarLenValCols = valMarsh.nonNullVarLenCols(val);
+
+ final TupleAssembler asm = new TupleAssembler(schema, size, nonNullVarLenKeyCols, nonNullVarLenValCols);
+
+ keyMarsh.writeObject(key, asm);
+ valMarsh.writeObject(val, asm); // TODO: support tomstones.
+
+ return asm.build();
+ }
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java
new file mode 100644
index 0000000..d1e0a12
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/Marshaller.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import org.apache.ignite.internal.schema.Tuple;
+import org.apache.ignite.internal.schema.TupleAssembler;
+
+/**
+ * Marshaller interface.
+ */
+public interface Marshaller {
+ /**
+ * Counts number non-null fields of variable length types.
+ *
+ * @param obj Object to analyze.
+ * @return Amount of non-null fields of variable length types.
+ * @throws SerializationException If failed.
+ */
+ //TODO: do we really need this to be 'public'? Would package-private in abstract class be better?
+ int nonNullVarLenCols(Object obj) throws SerializationException;
+
+ /**
+ * Reads object field value mapped to column of given index in schema.
+ *
+ * @param obj Object.
+ * @param colIdx Column index.
+ * @return Field value.
+ * @throws SerializationException If failed.
+ */
+ Object value(Object obj, int colIdx) throws SerializationException;
+
+ /**
+ * Reads object from tuple.
+ *
+ * @param reader Tuple reader.
+ * @return Object.
+ * @throws SerializationException If failed.
+ */
+ Object readObject(Tuple reader) throws SerializationException;
+
+ /**
+ * Write object to tuple.
+ *
+ * @param obj Object.
+ * @param writer Tuple writer.
+ * @throws SerializationException If failed.
+ */
+ void writeObject(Object obj, TupleAssembler writer) throws SerializationException;
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/ObjectFactory.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/ObjectFactory.java
new file mode 100644
index 0000000..f3b6520
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/ObjectFactory.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * Object factory.
+ */
+// TODO: Rewrite to direct field access via Unsafe to bypass security checks.
+// TODO: Extract interface, move to java-8 profile and add Java9+ implementation using VarHandles.
+class ObjectFactory<T> {
+ /**
+ * Creates factory for class.
+ *
+ * @param tClass Class.
+ * @return Object factory.
+ */
+ static <T> ObjectFactory<T> classFactory(Class<T> tClass) {
+ try {
+ return new ObjectFactory<>(tClass.getDeclaredConstructor());
+ }
+ catch (NoSuchMethodException e) {
+ throw new IllegalStateException("No default constructor found for class: " + tClass.getSimpleName());
+ }
+ }
+
+ /** Constructor for class. */
+ private final Constructor<T> ctor;
+
+ /**
+ * Constructor.
+ *
+ * @param ctor Class constructor for factory.
+ */
+ private ObjectFactory(Constructor<T> ctor) {
+ this.ctor = ctor;
+ }
+
+ /**
+ * Creates new class instance using default constructor.
+ *
+ * @return New instance of class.
+ * @throws IllegalStateException If failed.
+ */
+ public T newInstance() throws IllegalStateException {
+ try {
+ return ctor.newInstance();
+ }
+ catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
+ throw new IllegalStateException("Failed to instantiate class: " + ctor.getDeclaringClass(), e);
+ }
+ }
+}
diff --git a/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializationException.java b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializationException.java
new file mode 100644
index 0000000..4e3368e
--- /dev/null
+++ b/modules/commons/src/main/java/org/apache/ignite/internal/schema/marshaller/SerializationException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.schema.marshaller;
+
+public class SerializationException extends Exception {
+ public SerializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SerializationException(Throwable cause) {
+ super(cause);
+ }
+}
[ignite] 02/03: Add JUnit 5 support.
Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-13618
in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 71a9439a18ea25752611c4c51daeafb11eb9af7c
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Wed Nov 11 22:57:14 2020 +0300
Add JUnit 5 support.
---
modules/commons/pom.xml | 20 ++++++++++--
.../apache/ignite/internal/schema/ColumnTest.java | 5 +--
.../apache/ignite/internal/schema/ColumnsTest.java | 38 ++++++++++++++++------
.../ignite/internal/schema/NativeTypeTest.java | 34 ++++++++++---------
.../ignite/internal/schema/SchemaTestSuite.java | 8 ++---
.../apache/ignite/internal/schema/TupleTest.java | 24 ++++++++++----
6 files changed, 88 insertions(+), 41 deletions(-)
diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml
index 562fd06..ad7636f 100644
--- a/modules/commons/pom.xml
+++ b/modules/commons/pom.xml
@@ -144,9 +144,23 @@
<dependencies>
<dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
+ <groupId>org.jetbrains</groupId>
+ <artifactId>annotations</artifactId>
+ <version>${jetbrains.annotations.version}</version>
+ </dependency>
+
+ <!--JUnit 5-->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit.jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-runner</artifactId>
+ <version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnTest.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnTest.java
index 7725500..ddc5b74 100644
--- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnTest.java
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnTest.java
@@ -18,15 +18,16 @@
package org.apache.ignite.internal.schema;
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
*
*/
public class ColumnTest {
/**
+ *
*/
@Test
public void testCompareColumns() {
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnsTest.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnsTest.java
index a0d859e..93e5e45 100644
--- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnsTest.java
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/ColumnsTest.java
@@ -17,16 +17,18 @@
package org.apache.ignite.internal.schema;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
*/
public class ColumnsTest {
/**
+ *
*/
@Test
public void testFixsizeIndex() {
@@ -40,13 +42,14 @@ public class ColumnsTest {
assertEquals(-1, cols.firstVarlengthColumn());
for (int c = 0; c < cols.length(); c++)
- Assert.assertTrue(cols.isFixedSize(c));
+ assertTrue(cols.isFixedSize(c));
assertEquals(1, cols.nullMapSize());
assertEquals(3, cols.numberOfFixsizeColumns());
}
/**
+ *
*/
@Test
public void testVarsizeIndex() {
@@ -60,13 +63,14 @@ public class ColumnsTest {
assertEquals(0, cols.firstVarlengthColumn());
for (int c = 0; c < cols.length(); c++)
- Assert.assertFalse(cols.isFixedSize(c));
+ assertFalse(cols.isFixedSize(c));
assertEquals(1, cols.nullMapSize());
assertEquals(0, cols.numberOfFixsizeColumns());
}
/**
+ *
*/
@Test
public void testMixedIndex() {
@@ -82,9 +86,9 @@ public class ColumnsTest {
for (int c = 0; c < cols.length(); c++) {
if (c < cols.firstVarlengthColumn())
- Assert.assertTrue(cols.isFixedSize(c));
+ assertTrue(cols.isFixedSize(c));
else
- Assert.assertFalse(cols.isFixedSize(c));
+ assertFalse(cols.isFixedSize(c));
}
assertEquals(1, cols.nullMapSize());
@@ -92,6 +96,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testNullMapSize() {
@@ -111,6 +116,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeNoVarlenIncomplete1Byte() {
@@ -128,6 +134,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeNoVarlenFull1Byte() {
@@ -146,6 +153,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeNoVarlenIncomplete2Bytes() {
@@ -166,6 +174,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeNoVarlenFull2Bytes() {
@@ -192,6 +201,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeVarlenIncomplete1Byte() {
@@ -209,6 +219,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeVarlenFull1Byte() {
@@ -227,6 +238,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeVarlenIncomplete2Bytes1() {
@@ -246,6 +258,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeVarlenIncomplete2Bytes2() {
@@ -267,6 +280,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeVarlenIncomplete2Bytes3() {
@@ -288,6 +302,7 @@ public class ColumnsTest {
}
/**
+ *
*/
@Test
public void testFoldSizeVarlenFull2Bytes() {
@@ -314,6 +329,7 @@ public class ColumnsTest {
}
/**
+ *
*/
private void checkColumnFolding(Column[] colDef) {
Columns cols = new Columns(colDef);
@@ -328,6 +344,7 @@ public class ColumnsTest {
}
/**
+ *
*/
private void incrementMask(boolean[] mask) {
boolean add = true;
@@ -339,6 +356,7 @@ public class ColumnsTest {
}
/**
+ *
*/
private void checkSize(Columns cols, Column[] colDef, boolean[] nullMasks) {
// Iterate over bytes first
@@ -353,7 +371,7 @@ public class ColumnsTest {
if (idx >= cols.numberOfFixsizeColumns())
break;
- Assert.assertTrue(colDef[idx].type().spec().fixedLength());
+ assertTrue(colDef[idx].type().spec().fixedLength());
if (nullMasks[idx])
// set bit in the mask (indicate null value).
@@ -363,12 +381,12 @@ public class ColumnsTest {
size += colDef[idx].type().length();
}
- assertEquals("Failed [b=" + b + ", mask=" + mask + ']',
- size, cols.foldFixedLength(b, mask));
+ assertEquals(size, cols.foldFixedLength(b, mask), "Failed [b=" + b + ", mask=" + mask + ']');
}
}
/**
+ *
*/
private static Column[] columns(int size) {
Column[] ret = new Column[size];
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/NativeTypeTest.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/NativeTypeTest.java
index d2cf2a5..30b36dd 100644
--- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/NativeTypeTest.java
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/NativeTypeTest.java
@@ -17,51 +17,55 @@
package org.apache.ignite.internal.schema;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
*
*/
public class NativeTypeTest {
/**
+ *
*/
@Test
public void testCompareFixlenVarlen() {
- Assert.assertTrue(NativeType.BYTE.compareTo(NativeType.STRING) < 0);
- Assert.assertTrue(NativeType.BYTE.compareTo(NativeType.BYTES) < 0);
+ assertTrue(NativeType.BYTE.compareTo(NativeType.STRING) < 0);
+ assertTrue(NativeType.BYTE.compareTo(NativeType.BYTES) < 0);
- Assert.assertTrue(NativeType.INTEGER.compareTo(NativeType.STRING) < 0);
- Assert.assertTrue(NativeType.INTEGER.compareTo(NativeType.BYTES) < 0);
+ assertTrue(NativeType.INTEGER.compareTo(NativeType.STRING) < 0);
+ assertTrue(NativeType.INTEGER.compareTo(NativeType.BYTES) < 0);
- Assert.assertTrue(NativeType.LONG.compareTo(NativeType.STRING) < 0);
- Assert.assertTrue(NativeType.LONG.compareTo(NativeType.BYTES) < 0);
+ assertTrue(NativeType.LONG.compareTo(NativeType.STRING) < 0);
+ assertTrue(NativeType.LONG.compareTo(NativeType.BYTES) < 0);
- Assert.assertTrue(NativeType.UUID.compareTo(NativeType.STRING) < 0);
- Assert.assertTrue(NativeType.UUID.compareTo(NativeType.BYTES) < 0);
+ assertTrue(NativeType.UUID.compareTo(NativeType.STRING) < 0);
+ assertTrue(NativeType.UUID.compareTo(NativeType.BYTES) < 0);
}
/**
+ *
*/
@Test
public void testCompareFixlenBySize() {
- Assert.assertTrue(NativeType.SHORT.compareTo(NativeType.INTEGER) < 0);
- Assert.assertTrue(NativeType.INTEGER.compareTo(NativeType.LONG) < 0);
- Assert.assertTrue(NativeType.LONG.compareTo(NativeType.UUID) < 0);
+ assertTrue(NativeType.SHORT.compareTo(NativeType.INTEGER) < 0);
+ assertTrue(NativeType.INTEGER.compareTo(NativeType.LONG) < 0);
+ assertTrue(NativeType.LONG.compareTo(NativeType.UUID) < 0);
}
/**
+ *
*/
@Test
public void testCompareFixlenByDesc() {
- Assert.assertTrue(NativeType.FLOAT.compareTo(NativeType.INTEGER) < 0);
+ assertTrue(NativeType.FLOAT.compareTo(NativeType.INTEGER) < 0);
}
/**
+ *
*/
@Test
public void testCompareVarlenByDesc() {
- Assert.assertTrue(NativeType.BYTES.compareTo(NativeType.STRING) < 0);
+ assertTrue(NativeType.BYTES.compareTo(NativeType.STRING) < 0);
}
}
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java
index 93e489b..3eded6a 100644
--- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/SchemaTestSuite.java
@@ -17,15 +17,15 @@
package org.apache.ignite.internal.schema;
+import org.junit.platform.runner.JUnitPlatform;
+import org.junit.platform.suite.api.SelectClasses;
import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
/**
*
*/
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
+@RunWith(JUnitPlatform.class)
+@SelectClasses({
NativeTypeTest.class,
ColumnTest.class,
ColumnsTest.class,
diff --git a/modules/commons/src/test/java/org/apache/ignite/internal/schema/TupleTest.java b/modules/commons/src/test/java/org/apache/ignite/internal/schema/TupleTest.java
index 20fe7b4..afe58c6 100644
--- a/modules/commons/src/test/java/org/apache/ignite/internal/schema/TupleTest.java
+++ b/modules/commons/src/test/java/org/apache/ignite/internal/schema/TupleTest.java
@@ -21,9 +21,8 @@ import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Random;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import static org.apache.ignite.internal.schema.NativeType.BYTE;
import static org.apache.ignite.internal.schema.NativeType.BYTES;
@@ -34,7 +33,8 @@ import static org.apache.ignite.internal.schema.NativeType.LONG;
import static org.apache.ignite.internal.schema.NativeType.SHORT;
import static org.apache.ignite.internal.schema.NativeType.STRING;
import static org.apache.ignite.internal.schema.NativeType.UUID;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Tests tuple assembling and reading.
@@ -44,8 +44,9 @@ public class TupleTest {
private Random rnd;
/**
+ *
*/
- @Before
+ @BeforeEach
public void initRandom() {
long seed = System.currentTimeMillis();
@@ -55,6 +56,7 @@ public class TupleTest {
}
/**
+ *
*/
@Test
public void testFixedSizes() {
@@ -86,6 +88,7 @@ public class TupleTest {
}
/**
+ *
*/
@Test
public void testVariableSizes() {
@@ -111,6 +114,7 @@ public class TupleTest {
}
/**
+ *
*/
@Test
public void testMixedSizes() {
@@ -128,6 +132,7 @@ public class TupleTest {
}
/**
+ *
*/
private void checkSchema(Column[] keyCols, Column[] valCols) {
checkSchemaShuffled(keyCols, valCols);
@@ -139,6 +144,7 @@ public class TupleTest {
}
/**
+ *
*/
private void checkSchemaShuffled(Column[] keyCols, Column[] valCols) {
SchemaDescriptor sch = new SchemaDescriptor(1, new Columns(keyCols), new Columns(valCols));
@@ -167,6 +173,7 @@ public class TupleTest {
}
/**
+ *
*/
private Object[] sequence(SchemaDescriptor schema) {
Object[] res = new Object[schema.length()];
@@ -181,6 +188,7 @@ public class TupleTest {
}
/**
+ *
*/
private Object generateRandomValue(NativeType type) {
switch (type.spec()) {
@@ -249,6 +257,7 @@ public class TupleTest {
}
/**
+ *
*/
private void checkValues(SchemaDescriptor schema, Object... vals) {
assertEquals(schema.keyColumns().length() + schema.valueColumns().length(), vals.length);
@@ -355,13 +364,14 @@ public class TupleTest {
NativeTypeSpec type = schema.column(i).type().spec();
if (type == NativeTypeSpec.BYTES)
- Assert.assertArrayEquals((byte[])vals[i], (byte[])NativeTypeSpec.BYTES.objectValue(tup, i));
+ assertArrayEquals((byte[])vals[i], (byte[])NativeTypeSpec.BYTES.objectValue(tup, i));
else
- Assert.assertEquals(vals[i], type.objectValue(tup, i));
+ assertEquals(vals[i], type.objectValue(tup, i));
}
}
/**
+ *
*/
private void shuffle(Column[] cols) {
Collections.shuffle(Arrays.asList(cols));
[ignite] 01/03: Add checkstyle plugin. Add license check plugin.
Posted by am...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
amashenkov pushed a commit to branch ignite-13618
in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 6562730a6d1e4e160052eec5b0204d3d1df111bb
Author: Andrew Mashenkov <an...@gmail.com>
AuthorDate: Wed Nov 11 22:56:51 2020 +0300
Add checkstyle plugin.
Add license check plugin.
---
modules/commons/pom.xml | 124 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 122 insertions(+), 2 deletions(-)
diff --git a/modules/commons/pom.xml b/modules/commons/pom.xml
index 7264e5b..562fd06 100644
--- a/modules/commons/pom.xml
+++ b/modules/commons/pom.xml
@@ -29,6 +29,119 @@
<version>3.0.0-SNAPSHOT</version>
<url>http://ignite.apache.org</url>
+ <properties> <!-- TODO: Move section to some parent module. -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <jetbrains.annotations.version>20.1.0</jetbrains.annotations.version>
+ <junit.jupiter.version>5.7.0</junit.jupiter.version>
+ <junit.platform.version>1.7.0</junit.platform.version>
+
+ <apache.rat.plugin.version>0.13</apache.rat.plugin.version>
+ <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
+ <maven.surefire.plugin.version>3.0.0-M4</maven.surefire.plugin.version>
+ <maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version>
+ <checkstyle.puppycrawl.version>8.37</checkstyle.puppycrawl.version>
+ </properties>
+
+ <profiles> <!-- TODO: Move section to some parent module. -->
+ <profile>
+ <id>checkstyle</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${maven.checkstyle.plugin.version}</version>
+ <executions>
+ <execution>
+ <id>style</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+ <consoleOutput>true</consoleOutput>
+ <logViolationsToConsole>true</logViolationsToConsole>
+ <failsOnError>true</failsOnError>
+ <failOnViolation>true</failOnViolation>
+ <outputFile>${project.build.directory}/checkstyle-result.xml</outputFile>
+ <configLocation>../checkstyle/checkstyle.xml</configLocation>
+ <suppressionsLocation>../checkstyle/checkstyle-suppressions.xml
+ </suppressionsLocation>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ <excludes>**/generated/**/*</excludes>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${checkstyle.puppycrawl.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ <profile>
+ <id>check-licenses</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${apache.rat.plugin.version}</version>
+ <configuration>
+ <addDefaultLicenseMatchers>true</addDefaultLicenseMatchers>
+ <licenses>
+ <license implementation="org.apache.rat.analysis.license.FullTextMatchingLicense">
+ <licenseFamilyCategory>IAL20</licenseFamilyCategory>
+ <licenseFamilyName>Ignite Apache License 2.0</licenseFamilyName>
+ <fullText>
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ </fullText>
+ </license>
+ </licenses>
+ <licenseFamilies>
+ <licenseFamily implementation="org.apache.rat.license.SimpleLicenseFamily">
+ <familyName>Ignite Apache License 2.0</familyName>
+ </licenseFamily>
+ </licenseFamilies>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>work/**</exclude>
+ <exclude>**/target/**</exclude>
+ </excludes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -37,17 +150,24 @@
<scope>test</scope>
</dependency>
</dependencies>
- <build>
+
+ <build> <!-- TODO: Move section to some parent module. -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.7.0</version>
+ <version>${maven.compiler.plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${maven.surefire.plugin.version}</version>
+ </plugin>
</plugins>
</build>
</project>