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

feat(api): use new storagev2 interfaces #3833

Merged
merged 5 commits into from Mar 7, 2023

Conversation

aloknerurkar
Copy link
Contributor

@aloknerurkar aloknerurkar commented Feb 24, 2023

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

  • API package to use the new storer interface.
  • Mock storer implementation for the tests
  • Tests for Mock storer and adjusting original tests
  • Change in openapi spec

This change is Reviewable

// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package mockstorer
Copy link
Member

@istae istae Feb 24, 2023

Choose a reason for hiding this comment

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

why do we need a mock storer? Wouldn't it be better to use the real thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually, for unit tests we mock the objects that the package uses and are not defined in the package. The storer should be tested separately. Having API pkg unit tests depend on the actual storer implementation correctness is not right. There could be bugs in the implementation etc. The goal of the unit tests here is just to ensure the code in the api pkg files is correct.

The type of tests you are mentioning are integration tests. We can have these separately. Or we can develop beekeeper tests that will do this. We will probably have to change a bunch of those anyway, so we can even add some. Along with this, we need to provide debug APIs for showing storer state to verify in the tests.

Copy link
Member

@istae istae Feb 27, 2023

Choose a reason for hiding this comment

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

Having API pkg unit tests depend on the actual storer implementation correctness is not right. There could be bugs in the implementation etc

I don't understand this. We are not mocking here something complex like kademlia that's needs external connections.
We are mocking something that can be created as easily as storer.New(ctx context.Context, "", opts)

But I get it, we don't really want to spend the energy modifying already existing tests.

pkg/localstorev2/storer.go Outdated Show resolved Hide resolved
// Iterate over chunks in no particular order.
Iterate(context.Context, IterateChunkFn) error
}

type ReadOnlyChunkStore interface {
Getter
Copy link
Contributor

Choose a reason for hiding this comment

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

What about io.Closer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now this interface is just being used to access the local chunkstore. We dont want to manage the chunkstore on the caller side. So closer would anyway be a noop.

pkg/api/api.go Outdated Show resolved Hide resolved
pkg/api/api.go Outdated Show resolved Hide resolved
@@ -353,25 +348,18 @@ func (s *Service) Close() error {

// getOrCreateTag attempts to get the tag if an id is supplied, and returns an error if it does not exist.
// If no id is supplied, it will attempt to create a new tag with a generated name and return it.
func (s *Service) getOrCreateTag(tagUid string) (*tags.Tag, bool, error) {
func (s *Service) getOrCreateSessionID(tagUid uint64) (uint64, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can register this as a hook in preMapHooks similar to the resolveNameOrAddress method. That way you'll just use the tag on the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the problem is the usage is different in different APIs. For eg we create a tag only when deferred upload/pin flag is set in header. But this is not always true, sometime we will create a tag by default. Can this be handled in premaphook?

pkg/api/api.go Outdated Show resolved Hide resolved
pkg/api/pin.go Outdated Show resolved Hide resolved
pkg/api/router.go Outdated Show resolved Hide resolved
pkg/api/soc.go Outdated Show resolved Hide resolved
return err
}

err = uploaderSession.Put(ctx, c)
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to check the error, the following will do: return uploaderSession.Put(ctx, c).

pkg/api/api.go Outdated Show resolved Hide resolved
pkg/api/api_test.go Outdated Show resolved Hide resolved
pkg/api/bytes.go Outdated Show resolved Hide resolved
@aloknerurkar aloknerurkar merged commit 7ff9719 into localstorev2.0-integration Mar 7, 2023
@aloknerurkar aloknerurkar deleted the apipkg branch March 7, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants