Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

feat: moving a testing class from java-storage-nio to java-storage - #345

Closed
dmitry-fa wants to merge 3 commits into
googleapis:masterfrom
dmitry-fa:nio-merge
Closed

dmitry-fa wants to merge 3 commits into
googleapis:masterfrom
dmitry-fa:nio-merge

Conversation

@dmitry-fa

Copy link
Copy Markdown
Contributor

Moving FakeStorageRpcTest class implementing the StorageRpc interface from java-storage-nio to java-storage. That will allow extending StorageRpc without breaking cross-project dependencies.

It was suggested to introduce a new artifact google-cloud-storage-testing, but I hope it's not necessary, because we already have a testing class included in the main java-storage artifact: com.google.cloud.storage.testingRemoteStorageHelper. Newly introduced class FakeStorageRpc borrowed from the Storage-Nio is placed next to it.

Fixes #242

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 2, 2020
@dmitry-fa dmitry-fa changed the title Nio merge feat: moving a testing class from java-storage-nio to java-storage Jun 2, 2020
@codecov

codecov Bot commented Jun 2, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #345 into master will increase coverage by 0.10%.
The diff coverage is 65.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #345      +/-   ##
============================================
+ Coverage     62.73%   62.83%   +0.10%     
- Complexity      554      623      +69     
============================================
  Files            31       32       +1     
  Lines          5023     5263     +240     
  Branches        480      521      +41     
============================================
+ Hits           3151     3307     +156     
- Misses         1707     1768      +61     
- Partials        165      188      +23     
Impacted Files Coverage Δ Complexity Δ
...m/google/cloud/storage/testing/FakeStorageRpc.java 65.00% <65.00%> (ø) 69.00 <69.00> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3b04dd...f32f7de. Read the comment docs.

public class FakeStorageRpc implements StorageRpc {

// fullname -> metadata
Map<String, StorageObject> metadata = new HashMap<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

private

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These fields are package-private intentionally for the sake of testability. It allows covering 'the fake functionality' by stronger tests.

// fullname -> future contents that will be visible on close.
Map<String, byte[]> futureContents = new HashMap<>();

private final boolean throwIfOption;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure what this field name means

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

}

// remove all files
public void reset() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you need this or could you just create a new object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can't say for sure. This class is used by Storage-Nio tests. reset() doesn't clear all the fields, perhaps it's used for testing of resumable upload. Anyway, to provide smoother migration I think we need to keep it for now.

throws StorageException {
// if non-null, then we check the file's at that generation.
Long generationMatch = null;
for (Option op : options.keySet()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

op --> option


@Override
public Tuple<String, byte[]> read(
StorageObject from, Map<Option, ?> options, long zposition, int zbytes)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

zposition? zbytes? what are these?

}
checkGeneration(key, generationMatch);
long position = zposition;
int bytes = zbytes;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

numBytes?

StorageObject from, Map<Option, ?> options, long position, OutputStream outputStream) {
// if non-null, then we check the file's at that generation.
Long generationMatch = null;
for (Option op : options.keySet()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

op --> option

if (metadata.containsKey(uploadId)) {
StorageObject storageObject = metadata.get(uploadId);
Long generation = storageObject.getGeneration();
if (null == generation) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

generation == null

@dmitry-fa

Copy link
Copy Markdown
Contributor Author

@elharo, thanks for looking. Now I see that this implementation is very nio specific, unlikely it will be used by anyone else. So, it's not a good idea to expose such a class.

Probably, the right way is to export a class implementing all StorageRpc methods to throw UnsupportedException and make FakeStorageRpc in Storage-Nio to extends it.

So, I'm closing this PR

@dmitry-fa dmitry-fa closed this Jun 2, 2020
@dmitry-fa
dmitry-fa deleted the nio-merge branch June 26, 2020 07:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Merge Storage-NIO library into this repository.

3 participants