You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2022/03/18 02:18:46 UTC
[GitHub] [avro] KyleSchoonover opened a new pull request #1606: AVRO-3458 Added tests for GenericRecord
KyleSchoonover opened a new pull request #1606:
URL: https://github.com/apache/avro/pull/1606
### Jira
- [ ] My PR addresses the following [Avro Jira](https://issues.apache.org/jira/browse/AVRO/) issues and references them in the PR title. For example, "AVRO-1234: My Avro PR"
- https://issues.apache.org/jira/browse/AVRO-3458
### Tests
- [ ] My PR does not need testing for this extremely good reason: It is just adding tests
### Commits
- [ ] My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](https://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Documentation
- [ ] In case of new functionality, my PR adds documentation that describes how to use it.
- All the public functions and the classes in the PR contain Javadoc that explain what it does
--
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: dev-unsubscribe@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on pull request #1606: AVRO-3458: Added tests for GenericRecord
Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on pull request #1606:
URL: https://github.com/apache/avro/pull/1606#issuecomment-1083042087
I usually wait for the checks to go green before approval. Can you fix the failed checks plz?
--
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@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] KyleSchoonover removed a comment on pull request #1606: AVRO-3458: Added tests for GenericRecord
Posted by GitBox <gi...@apache.org>.
KyleSchoonover removed a comment on pull request #1606:
URL: https://github.com/apache/avro/pull/1606#issuecomment-1074174174
> 1. GenericTests.cs already has many GenerricRecord related tests. Why are these tests in a seperate GenericRecordTests.cs file?
> 2. Could these tests utilize the mkRecord and other helper code implemenetd in GenericTests.cs?
> 3. schema definition strings are preferred to be defined as const/readonly/static fileds or use test case to specify them
1. These are unit tests specific to just GenericRecord.
2. It could, but the tests don't require something that complex
3. Moved the base schema to a const.
--
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@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] KyleSchoonover commented on pull request #1606: AVRO-3458: Added tests for GenericRecord
Posted by GitBox <gi...@apache.org>.
KyleSchoonover commented on pull request #1606:
URL: https://github.com/apache/avro/pull/1606#issuecomment-1074174173
--
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@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on a change in pull request #1606: AVRO-3458: Added tests for GenericRecord
Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on a change in pull request #1606:
URL: https://github.com/apache/avro/pull/1606#discussion_r831456252
##########
File path: lang/csharp/src/apache/test/Generic/GenericRecordTests.cs
##########
@@ -0,0 +1,202 @@
+using System;
+using System.Collections.Generic;
+using Avro.Generic;
+using NUnit.Framework;
+
+namespace Avro.test.Generic
+{
+ [TestFixture]
+ public class GenericRecordTests
+ {
+ private const string baseSchema = "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
+ "[{\"name\":\"f2\",\"type\":\"int\"},{\"name\":\"f1\",\"type\":\"boolean\"}]}";
+
+ [Test]
+ public void TestAddByFieldNameThrows()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ // Field does not exist
+ Assert.Throws<AvroException>(() => { genericRecord.Add("badField", "test"); });
+ }
+
+ [Test]
+ public void TestAddByPosition()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ genericRecord.Add(0, 2);
+
+ object value = genericRecord.GetValue(0);
+
+ Assert.IsNotNull(value);
+ Assert.IsTrue(value is int);
+ Assert.AreEqual(2, (int)value);
+ }
+
+ [Test]
+ public void TestAddByPositionThrows()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ Assert.Throws<IndexOutOfRangeException>(() => { genericRecord.Add(2, 2); });
+ }
+
+ [Test]
+ public void TestEquals()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ GenericRecord genericRecord2 = GetBaseGenericRecord();
+
+ Assert.IsTrue(genericRecord.Equals(genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsNotEqual()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ GenericRecord genericRecord2 = GetBaseGenericRecord();
+ genericRecord2.Add(0, 2);
+
+ Assert.IsFalse(genericRecord.Equals(genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsObject()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ object genericRecord2 = genericRecord;
+
+ Assert.IsTrue(genericRecord.Equals(genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsObjectNotEqual()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ GenericRecord genericRecord2 = GetBaseGenericRecord();
+ genericRecord2.Add(0, 2);
+
+ Assert.IsFalse(genericRecord.Equals((object)genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsObjectNullObject()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ Assert.IsFalse(genericRecord.Equals((object)null));
+ }
+
+ [Test]
+ public void TestGetHashCode()
+ {
+ int hashCode = GetBaseGenericRecord().GetHashCode();
+ Assert.IsTrue(hashCode > 0);
+ }
+
+ [Test]
+ public void TestGetValue()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ object value = genericRecord.GetValue(0);
+
+ Assert.IsNotNull(value);
+ Assert.IsTrue(value is int);
+ Assert.AreEqual(1, (int)value);
+ }
+
+ [Test]
+ public void TestKeyValueLookup()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ // Key Exists
+ object existingKey = genericRecord["f2"];
+ Assert.IsNotNull(existingKey);
+ Assert.IsTrue(existingKey is int);
+ }
+
+ [Test]
+ public void TestKeyValueLookupThrows()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ // Key does not exist
+ Assert.Throws<KeyNotFoundException>(() => { object missingKey = genericRecord["badField"]; });
Review comment:
Resolve this CodeQL warning plz
--
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@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] zcsizmadia commented on pull request #1606: AVRO-3458: Added tests for GenericRecord
Posted by GitBox <gi...@apache.org>.
zcsizmadia commented on pull request #1606:
URL: https://github.com/apache/avro/pull/1606#issuecomment-1073349366
1. GenericTests.cs already has many GenerricRecord related tests. Why are these tests in a seperate GenericRecordTests.cs file?
2. Could these tests utilize the mkRecord and other helper code implemenetd in GenericTests.cs?
3. schema definition strings are preferred to be defined as const/readonly/static fileds or use test case to specify them
--
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@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [avro] KyleSchoonover commented on a change in pull request #1606: AVRO-3458: Added tests for GenericRecord
Posted by GitBox <gi...@apache.org>.
KyleSchoonover commented on a change in pull request #1606:
URL: https://github.com/apache/avro/pull/1606#discussion_r838119832
##########
File path: lang/csharp/src/apache/test/Generic/GenericRecordTests.cs
##########
@@ -0,0 +1,202 @@
+using System;
+using System.Collections.Generic;
+using Avro.Generic;
+using NUnit.Framework;
+
+namespace Avro.test.Generic
+{
+ [TestFixture]
+ public class GenericRecordTests
+ {
+ private const string baseSchema = "{\"type\":\"record\",\"name\":\"r\",\"fields\":" +
+ "[{\"name\":\"f2\",\"type\":\"int\"},{\"name\":\"f1\",\"type\":\"boolean\"}]}";
+
+ [Test]
+ public void TestAddByFieldNameThrows()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ // Field does not exist
+ Assert.Throws<AvroException>(() => { genericRecord.Add("badField", "test"); });
+ }
+
+ [Test]
+ public void TestAddByPosition()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ genericRecord.Add(0, 2);
+
+ object value = genericRecord.GetValue(0);
+
+ Assert.IsNotNull(value);
+ Assert.IsTrue(value is int);
+ Assert.AreEqual(2, (int)value);
+ }
+
+ [Test]
+ public void TestAddByPositionThrows()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ Assert.Throws<IndexOutOfRangeException>(() => { genericRecord.Add(2, 2); });
+ }
+
+ [Test]
+ public void TestEquals()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ GenericRecord genericRecord2 = GetBaseGenericRecord();
+
+ Assert.IsTrue(genericRecord.Equals(genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsNotEqual()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ GenericRecord genericRecord2 = GetBaseGenericRecord();
+ genericRecord2.Add(0, 2);
+
+ Assert.IsFalse(genericRecord.Equals(genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsObject()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ object genericRecord2 = genericRecord;
+
+ Assert.IsTrue(genericRecord.Equals(genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsObjectNotEqual()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+ GenericRecord genericRecord2 = GetBaseGenericRecord();
+ genericRecord2.Add(0, 2);
+
+ Assert.IsFalse(genericRecord.Equals((object)genericRecord2));
+ }
+
+ [Test]
+ public void TestEqualsObjectNullObject()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ Assert.IsFalse(genericRecord.Equals((object)null));
+ }
+
+ [Test]
+ public void TestGetHashCode()
+ {
+ int hashCode = GetBaseGenericRecord().GetHashCode();
+ Assert.IsTrue(hashCode > 0);
+ }
+
+ [Test]
+ public void TestGetValue()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ object value = genericRecord.GetValue(0);
+
+ Assert.IsNotNull(value);
+ Assert.IsTrue(value is int);
+ Assert.AreEqual(1, (int)value);
+ }
+
+ [Test]
+ public void TestKeyValueLookup()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ // Key Exists
+ object existingKey = genericRecord["f2"];
+ Assert.IsNotNull(existingKey);
+ Assert.IsTrue(existingKey is int);
+ }
+
+ [Test]
+ public void TestKeyValueLookupThrows()
+ {
+ GenericRecord genericRecord = GetBaseGenericRecord();
+
+ // Key does not exist
+ Assert.Throws<KeyNotFoundException>(() => { object missingKey = genericRecord["badField"]; });
Review comment:
Changed to discard
--
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@avro.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org