You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/10/29 19:55:31 UTC

[GitHub] [nifi] pgyori commented on a change in pull request #5381: NIFI-9206: Add RemoveRecordField processor and implement the ability …

pgyori commented on a change in pull request #5381:
URL: https://github.com/apache/nifi/pull/5381#discussion_r739498158



##########
File path: nifi-commons/nifi-record/src/test/java/org/apache/nifi/serialization/TestSimpleRecordSchema.java
##########
@@ -93,21 +93,142 @@ public void testHashCodeAndEqualsWithSelfReferencingSchema() {
     }
 
     @Test
-    public void testFieldsArentCheckedInEqualsIfNameAndNamespaceMatch() {
-        final RecordField testField = new RecordField("test", RecordFieldType.STRING.getDataType());
+    public void testEqualsSimpleSchema() {
+        // GIVEN
+        final String nameOfField1 = "field1";
+        final String nameOfField2 = "field2";
+        final DataType typeOfField1 = RecordFieldType.INT.getDataType();
+        final DataType typeOfField2 = RecordFieldType.STRING.getDataType();
+        final String schemaName = "schemaName";
+        final String namespace = "namespace";
+
+        final SimpleRecordSchema schema1 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField2, schemaName, namespace);
+        final SimpleRecordSchema schema2 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField2, schemaName, namespace);
+
+        // WHEN, THEN
+        assertTrue(schema1.equals(schema2));
+    }
 
-        final SimpleRecordSchema schema1 = new SimpleRecordSchema(SchemaIdentifier.EMPTY);
-        schema1.setSchemaName("name");
-        schema1.setSchemaNamespace("namespace");
-        schema1.setFields(Collections.singletonList(testField));
+    @Test
+    public void testEqualsSimpleSchemaEvenIfSchemaNameAndNameSpaceAreDifferent() {
+        // GIVEN
+        final String nameOfField1 = "field1";
+        final String nameOfField2 = "field2";
+        final DataType typeOfField1 = RecordFieldType.INT.getDataType();
+        final DataType typeOfField2 = RecordFieldType.STRING.getDataType();
+        final String schemaName1 = "schemaName1";
+        final String schemaName2 = "schemaName2";
+        final String namespace1 = "namespace1";
+        final String namespace2 = "namespace2";
+
+        final SimpleRecordSchema schema1 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField2, schemaName1, namespace1);
+        final SimpleRecordSchema schema2 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField2, schemaName2, namespace2);
+
+        // WHEN, THEN
+        assertTrue(schema1.equals(schema2));
+    }
 
-        SimpleRecordSchema schema2 = Mockito.spy(new SimpleRecordSchema(SchemaIdentifier.EMPTY));
-        schema2.setSchemaName("name");
-        schema2.setSchemaNamespace("namespace");
-        schema2.setFields(Collections.singletonList(testField));
+    @Test
+    public void testNotEqualsSimpleSchemaDifferentTypes() {
+        // GIVEN
+        final String nameOfField1 = "field1";
+        final String nameOfField2 = "field2";
+        final DataType typeOfField1 = RecordFieldType.INT.getDataType();
+        final DataType typeOfField2 = RecordFieldType.STRING.getDataType();
+        final String schemaName = "schemaName";
+        final String namespace = "namespace";
+
+        final SimpleRecordSchema schema1 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField1, schemaName, namespace);
+        final SimpleRecordSchema schema2 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField2, schemaName, namespace);
+
+        // WHEN, THEN
+        assertFalse(schema1.equals(schema2));
+    }
+
+    @Test
+    public void testNotEqualsSimpleSchemaDifferentFieldNames() {
+        // GIVEN
+        final String nameOfField1 = "field1";
+        final String nameOfField2 = "field2";
+        final String nameOfField3 = "field3";
+        final DataType typeOfField1 = RecordFieldType.INT.getDataType();
+        final DataType typeOfField2 = RecordFieldType.STRING.getDataType();
+        final String schemaName = "schemaName";
+        final String namespace = "namespace";
+
+        final SimpleRecordSchema schema1 = createSchemaWithTwoFields(nameOfField1, nameOfField2, typeOfField1, typeOfField2, schemaName, namespace);
+        final SimpleRecordSchema schema2 = createSchemaWithTwoFields(nameOfField1, nameOfField3, typeOfField1, typeOfField2, schemaName, namespace);
+
+        // WHEN, THEN
+        assertFalse(schema1.equals(schema2));
+    }
+
+    @Test
+    public void testEqualsRecursiveSchema() {
+        final String field1 = "field1";
+        final String field2 = "field2";
+        final String schemaName = "schemaName";
+        final String namespace = "namespace";
+
+        final SimpleRecordSchema schema1 = createRecursiveSchema(field1, field2, schemaName, namespace);
+        final SimpleRecordSchema schema2 = createRecursiveSchema(field1, field2, schemaName, namespace);
 
         assertTrue(schema1.equals(schema2));
-        Mockito.verify(schema2, Mockito.never()).getFields();
+        assertTrue(schema2.equals(schema1));
+    }
+
+    @Test(expected = StackOverflowError.class)

Review comment:
       I know that this is super weird. This was the behavior even before I started modifying the code and I want to draw attention to this. Fixing this in SimpleRecordSchema.equals() alters the behavior heavily and still leaves open questions. I'm open to ideas and suggestions.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org