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

[Test] Assume unknown blockID in LocalFileHandlerTestBase #478

Merged
merged 3 commits into from
Jan 16, 2023

Conversation

kaijchen
Copy link
Contributor

@kaijchen kaijchen commented Jan 12, 2023

What changes were proposed in this pull request?

Split LocalFileHandlerTestBase#writeTestData() into generateBlocks() and writeTestData().
Pass List<Long> blockIds into LocalFileHandlerTestBase#calcSegmentBytes().

Why are the changes needed?

Followup #473.
To make the expected result corresponding to the state of LocalFileHandlerTestBase#ATOMIC_LONG.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

CI.

@codecov-commenter
Copy link

codecov-commenter commented Jan 12, 2023

Codecov Report

Merging #478 (c4d8ebe) into master (7f89d6f) will decrease coverage by 0.00%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##             master     #478      +/-   ##
============================================
- Coverage     58.78%   58.77%   -0.01%     
- Complexity     1704     1705       +1     
============================================
  Files           206      206              
  Lines         11471    11469       -2     
  Branches       1024     1023       -1     
============================================
- Hits           6743     6741       -2     
  Misses         4317     4317              
  Partials        411      411              
Impacted Files Coverage Δ
...rg/apache/uniffle/server/ShuffleServerMetrics.java 97.05% <0.00%> (-0.14%) ⬇️
...org/apache/uniffle/server/ShuffleFlushManager.java 84.04% <0.00%> (+0.08%) ⬆️
...che/uniffle/server/storage/HdfsStorageManager.java 93.84% <0.00%> (+0.09%) ⬆️
...g/apache/uniffle/server/ShuffleDataFlushEvent.java 83.67% <0.00%> (+0.34%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@advancedxy
Copy link
Contributor

Did a quick overview of the related code, I believe the better fix should be refactor org.apache.uniffle.storage.handler.impl.LocalFileHandlerTestBase#calcSegmentBytes by passing the correct wroteBlockList or just retrieve blocks from blockIdToData

In a real environment, the blockId could be random and generated concurrently. org.apache.uniffle.storage.handler.impl.LocalFileHandlerTestBase#ATOMIC_LONG seems to be a good way to simulate it.

also cc @zuston

@zuston
Copy link
Member

zuston commented Jan 12, 2023

just retrieve blocks from blockIdToData

I prefer to this solution

@kaijchen
Copy link
Contributor Author

or just retrieve blocks from blockIdToData

Not all blocks in blockIdToData are copied in LocalFileHandlerTestBase#calcSegmentBytes().

@zuston
Copy link
Member

zuston commented Jan 13, 2023

Not all blocks in blockIdToData are copied in LocalFileHandlerTestBase#calcSegmentBytes().

What about passing the correct wroteBlockList

@kaijchen kaijchen force-pushed the refactor-LocalFileHandlerTestBase branch from a8d2726 to 620464f Compare January 13, 2023 03:57
@kaijchen kaijchen changed the title [Test] Make LocalFileHandlerTestBase stateless [Test] Assume unknown blockID in LocalFileHandlerTestBase Jan 13, 2023
ShuffleWriteHandler writeHandler,
int num, int length,
Map<Long, byte[]> expectedData,
Set<Long> expectedBlockIds) throws Exception {
List<ShufflePartitionedBlock> blocks = Lists.newArrayList();
List<Long> blockIds = Lists.newArrayList();
Copy link
Member

Choose a reason for hiding this comment

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

Why not use Set<Long> expectedBlockIds directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give an example how to use expectedBlockIds in calcSegmentBytes?
I think we should preserve order and exclude the last block.

Copy link
Member

Choose a reason for hiding this comment

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

Like this?
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I got it when you mean TreeSet. However, I'm wondering if we should keep the current writeTestData() signature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use LinkedHashSet for expectedBlockIds?

The signature could retain or just changed to LinkedHashSet<Long>. This is the test method, we can change it at will.

@@ -80,7 +78,7 @@ public void testDataInconsistent() throws Exception {
int readBufferSize = 13;
int bytesPerSegment = ((readBufferSize / blockSize) + 1) * blockSize;
List<byte[]> segments = LocalFileHandlerTestBase.calcSegmentBytes(expectedData,
bytesPerSegment, actualWriteDataBlock);
bytesPerSegment, blockIds.subList(0, actualWriteDataBlock));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zuston because we need to get subList here.

Copy link
Member

Choose a reason for hiding this comment

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

The size of expectedBlockIds is expected in this method of calcSegmentBytes invoking. Right?

@kaijchen
Copy link
Contributor Author

kaijchen commented Jan 16, 2023

Thanks @zuston and @advancedxy for the review.
I have splitted LocalFileHandlerTestBase#writeTestData() into generateBlocks() and writeTestData().
How about that?

Copy link
Member

@zuston zuston left a comment

Choose a reason for hiding this comment

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

Left minor comment. Overall LGTM.

Map<Long, byte[]> expectedData, Set<Long> expectedBlockIds) throws Exception {
handler.write(blocks);
blocks.forEach(block -> expectedBlockIds.add(block.getBlockId()));
blocks.forEach(block -> expectedData.put(block.getBlockId(), block.getData()));
Copy link
Member

Choose a reason for hiding this comment

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

Why not do above two operations in one foreach ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no significant peformance difference. And I prefer do one thing at a time for clarity.

@advancedxy advancedxy merged commit ff9c36f into apache:master Jan 16, 2023
@advancedxy
Copy link
Contributor

Merging this. Thanks @kaijchen @zuston

@kaijchen
Copy link
Contributor Author

Thanks @advancedxy and @zuston for the review.

@kaijchen kaijchen deleted the refactor-LocalFileHandlerTestBase branch January 16, 2023 13:18
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.

None yet

4 participants