Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing CopyFrom method in OdataMessageReader and OdataMessageWriter to include Arraypool #1595

Merged
merged 12 commits into from
Nov 20, 2019

Conversation

Sreejithpin
Copy link
Contributor

Issues

There was an issue that OData.Core ICharArrayPool is not hooked up properly, which was causing lot of Large Object Heap allocations taking up lot of memory

Description

  • Added Arrayppol copying in ODataMessage reader and writer settings
  • Added test cases for checking the same
  • Added generic test method to compare 2 objects (deep copy)

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

N/A

@Sreejithpin Sreejithpin changed the title Changes and test Fixing CopyFrom method in OdataMessageReader and OdataMessageWriter to include Arraypool Nov 13, 2019
@@ -132,7 +132,7 @@ public void ODataMessageReaderCopyConstructorTest()
// Compare original and settings created from copy constructor after setting some values
settings.BaseUri = new Uri("http://www.odata.org");
settings.EnableCharactersCheck = true;
copyOfSettings = settings.Clone();
copyOfSettings = settings.Clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintended change.


}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line.

if (element1 == null || element2 == null)
{
diff.Add(string.Format("Value of items in Collection {0} does not match.", prop.Name));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line.

{
EvaluateDifferences(element1, element2, diff);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line.

<ItemGroup>
<Folder Include="References\" />
</ItemGroup>

</Project>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have any change? If it is a change that you did not intend then please revert this.


var differences = ValidationHelper.GetDifferences<ODataMessageWriterSettings>(this.settings, newSetting);
Assert.True(differences.Count == 0, String.Join(",", differences));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line.

@@ -357,7 +400,7 @@ public void PropertyGettersAndSettersTest()
MaxNestingDepth = maxNestingDepth,
},
Version = version,
LibraryCompatibility = library,
LibraryCompatibility = library,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert whitespace.


namespace Microsoft.OData.Tests
{
public class TestCharArrayPool : ICharArrayPool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember I had a default implementation for ICharArrayPool. Don't I?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kept the Testchararraypool as such to be reused later as the the testarraypool implementation was inside another class file.

@@ -281,6 +281,9 @@
<Compile Include="..\ScenarioTests\UriParser\TopAndSkipFunctionalTests.cs" />
<Compile Include="..\ScenarioTests\UriParser\VerificationHelpers.cs" />
<Compile Include="..\ScenarioTests\Writer\JsonLight\WriteFeedWithoutNavigationSourceTests.cs" />
<Compile Include="..\TestCharArrayPool.cs">
<Link>TestCharArrayPool.cs</Link>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add the for the Compile element?

@@ -450,6 +453,9 @@
<Compile Include="..\UriParser\Visitors\IsCollectionTranslatorTests.cs" />
<Compile Include="..\UriParser\Visitors\QueryNodeVisitorTests.cs" />
<Compile Include="..\UriParser\Visitors\SyntacticTreeVisitorTests.cs" />
<Compile Include="..\ValidationHelper.cs">
<Link>ValidationHelper.cs</Link>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add the for the Compile element?

@@ -1,147 +1,147 @@
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this file?

@@ -0,0 +1,27 @@
using Microsoft.OData.Buffers;
using System;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -0,0 +1,27 @@
using Microsoft.OData.Buffers;
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REsolved

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REsolved


namespace Microsoft.OData.Tests
{
public class ValidationHelper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class ValidationHelper [](start = 11, length = 22)

make it as "static class"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="copy"></param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add the comments, finish the comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="copy"></param>
/// <param name="diff"></param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

private static void EvaluateDifferences<T>(T obj, T copy, List<string> diff)
{

foreach (var prop in obj.GetType().GetProperties().Where(x => x.CanRead))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify the input and remove unused the line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

else
{
EvaluateDifferences(element1, element2, diff);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you can replace all by calling EvaluateDifferences again?

Copy link
Contributor Author

@Sreejithpin Sreejithpin Nov 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text for this contains collection, eg: "Values of Collection {0} does not match.". So to keep that text and any further modificatioins needed for collection did like this. Pls let me know if thats fine. Let me try anyway to make it more generic at a single place

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@@ -205,6 +205,9 @@ private void CompareMessageReaderSettings(ODataMessageReaderSettings expected, O
Assert.True(expected.MessageQuotas.MaxOperationsPerChangeset == actual.MessageQuotas.MaxOperationsPerChangeset, "MaxOperationsPerChangeset does not match");
Assert.True(expected.MessageQuotas.MaxNestingDepth == actual.MessageQuotas.MaxNestingDepth, "MaxNestingDepth does not match");
Assert.True(expected.MessageQuotas.MaxReceivedMessageSize == actual.MessageQuotas.MaxReceivedMessageSize, "MaxMessageSize does not match");

var differences = ValidationHelper.GetDifferences<ODataMessageReaderSettings>(expected, actual);
Assert.True(differences.Count == 0, String.Join(",", differences));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add the "GetDifferences" function call, how about the codes from Line 191 to Line 207?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to change the existing code. Existing lines will function as such

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my concern. It seems we verify the same twice.


In reply to: 348177998 [](ancestors = 348177998)

Sreejith Pazhampilly added 2 commits November 19, 2019 13:28
Added copyright, sorted usings etc
Restructured EvaluateDifferences
/// <param name="diff">List Of Differences</param>
/// <param name="objName">Optional parameter for objectname, to be used in differences string, default empty string</param>
/// <param name="isCollection">Optional parameter to see if its a collection, default false</param>
private static void EvaluateDifferences<T>(T obj, T copy, List<string> diff,string objName ="", bool isCollection =false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

,string objName ="" [](start = 83, length = 19)

add the whitespace correctly. for example:
add whitespace between the parameter, add the whitespace before and after "="?

Assert.True(expected.MessageQuotas.MaxReceivedMessageSize == actual.MessageQuotas.MaxReceivedMessageSize, "MaxMessageSize does not match");

var differences = ValidationHelper.GetDifferences<ODataMessageReaderSettings>(expected, actual);
Assert.True(differences.Count == 0, String.Join(",", differences));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  [](start = 79, length = 6)

remove the unused whitespace

Copy link
Member

@xuzhg xuzhg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@KanishManuja-MS KanishManuja-MS merged commit c2b53e8 into OData:master Nov 20, 2019
KanishManuja-MS pushed a commit to KanishManuja-MS/odata.net that referenced this pull request Nov 20, 2019
…o include Arraypool (OData#1595)

* Changes and test

* Fixing the build error

* Fixes based on Review Comments

Fixes based on Review Comments

* Update Microsoft.Test.OData.Tests.Client.NetCore.csproj

* Revert "Merge branch 'master' into UpdateCopyFromMethod"

This reverts commit 1345914, reversing
changes made to 9a786ed.

* Update Microsoft.Test.OData.Tests.Client.NetCore.csproj

Reverting Microsoft.Test.OData.Tests.Client.NetCore

* reverted stylecop buildnumber

reverted stylecop buildnumber as its already committed

* Fixed as per review comments

Added copyright, sorted usings etc

* Restructured EvaluateDifferences

Restructured EvaluateDifferences

* Update ValidationHelper.cs
KanishManuja-MS pushed a commit that referenced this pull request Nov 20, 2019
…o include Arraypool (#1595)

* Changes and test

* Fixing the build error

* Fixes based on Review Comments

Fixes based on Review Comments

* Update Microsoft.Test.OData.Tests.Client.NetCore.csproj

* Revert "Merge branch 'master' into UpdateCopyFromMethod"

This reverts commit 1345914, reversing
changes made to 9a786ed.

* Update Microsoft.Test.OData.Tests.Client.NetCore.csproj

Reverting Microsoft.Test.OData.Tests.Client.NetCore

* reverted stylecop buildnumber

reverted stylecop buildnumber as its already committed

* Fixed as per review comments

Added copyright, sorted usings etc

* Restructured EvaluateDifferences

Restructured EvaluateDifferences

* Update ValidationHelper.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants