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

Lab6 - Puppy Storer - alfredxiao #476

Closed
wants to merge 19 commits into from

Conversation

alfredxiao
Copy link
Collaborator

@alfredxiao alfredxiao commented Jun 24, 2019

Fixes #475

Review of colleague's PR #436

Changes proposed in this PR:

  • Implement Storer using map
  • Implement Storer using sync.map
  • Test using suite

@codecov
Copy link

codecov bot commented Jun 24, 2019

Codecov Report

Merging #476 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #476   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         107    110    +3     
  Lines        1861   1923   +62     
=====================================
+ Hits         1861   1923   +62
Impacted Files Coverage Δ
06_puppy/alfredxiao/syncstore.go 100% <100%> (ø)
06_puppy/alfredxiao/mapstore.go 100% <100%> (ø)
06_puppy/alfredxiao/main.go 100% <100%> (ø)

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 40114a7...02ed8ef. Read the comment docs.

@alfredxiao alfredxiao changed the title Lab6 alfredxiao Lab6 Puppy Storer - alfredxiao Jun 24, 2019
marksomething
marksomething previously approved these changes Jun 25, 2019
Copy link
Collaborator

@marksomething marksomething left a comment

Choose a reason for hiding this comment

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

Looks really good, nothing i can see that would make me not approve.

06_puppy/alfredxiao/mapstore.go Show resolved Hide resolved
06_puppy/alfredxiao/store_test.go Outdated Show resolved Hide resolved
t := s.T()
_ = s.store.CreatePuppy(Puppy{ID: "3", Colour: "Blue"})
p, err := s.store.ReadPuppy("3")
require.NoError(t, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the mix of require and assert?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

require is for not continuing with other assertions when it fails, assertions do not have this attribute. In this case, my thought was that if err is Error then there is no point in continuing.

06_puppy/alfredxiao/store_test.go Outdated Show resolved Hide resolved
06_puppy/alfredxiao/store_test.go Outdated Show resolved Hide resolved
"sync"
)

type syncStore struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting choice to make this private.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't make it private :)

@marksomething marksomething mentioned this pull request Jun 25, 2019
Copy link
Contributor

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

Gotta run now, but rushed, but should give you a start :)

06_puppy/alfredxiao/main.go Outdated Show resolved Hide resolved
06_puppy/alfredxiao/mapstore.go Outdated Show resolved Hide resolved
06_puppy/alfredxiao/mapstore.go Outdated Show resolved Hide resolved
06_puppy/alfredxiao/mapstore.go Outdated Show resolved Hide resolved
06_puppy/alfredxiao/store_test.go Outdated Show resolved Hide resolved
@alfredxiao alfredxiao changed the title Lab6 Puppy Storer - alfredxiao Lab6 - Puppy Storer - alfredxiao Jun 27, 2019
@alfredxiao alfredxiao requested a review from samuong as a code owner July 22, 2019 11:52
Copy link
Contributor

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

If you need help with this, please reach out and/or come over.

You'll also have to add a mutex to add agains race condition in the syncmap implementation (the point of using sync.Map is to protect your code from race conditions - make it "thread/goroutine safe").

Other than that looks pretty solid, well done.

data map[string]Puppy
}

func (s *mapStore) CreatePuppy(p Puppy) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use godoc for all public functions.

}

func (s *mapStore) UpdatePuppy(id string, p Puppy) error {
if id != p.ID {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why you'd have separate id field?

}

_, ok := s.data[id]
if !ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

if _, ok := s.data[id]; !ok {

same below.

"sync"
)

type syncStore struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't make it private :)

}

func (s *syncStore) CreatePuppy(p Puppy) string {
id := uuid.New().String()
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return fmt.Errorf("puppy with ID[%s] does not exists", p.ID)
}

s.data.Store(id, p)
Copy link
Contributor

Choose a reason for hiding this comment

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

load and store need to be guarded with Mutex or RWMutex to avoid race conditions.
dame for delete.

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.

Lab06 - Puppy Store
4 participants