-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added cache manager which handles caching on server. cache logic is now removed from cluster service to use cache manager instead. * Added domain service which allows searching for a domain. * added test for fetchDomainListNextPage and fixed bug in implementation * add test for sortDomainList * adding tests for getMatchingDomains * fixup failed conflict resolution
- Loading branch information
1 parent
9ce60e4
commit 9e4c44a
Showing
17 changed files
with
525 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const delay = time => new Promise(resolve => setTimeout(resolve, time)); | ||
|
||
module.exports = delay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const DOMAIN_LIST_DELAY_MS = 100; | ||
const DOMAIN_LIST_PAGE_SIZE = 100; | ||
const DOMAIN_LIST_SEARCH_SIZE = 10; | ||
|
||
module.exports = { | ||
DOMAIN_LIST_DELAY_MS, | ||
DOMAIN_LIST_PAGE_SIZE, | ||
DOMAIN_LIST_SEARCH_SIZE, | ||
}; |
52 changes: 52 additions & 0 deletions
52
server/router/services/domain-service/helpers/fetch-domain-list-next-page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const { DOMAIN_LIST_DELAY_MS, DOMAIN_LIST_PAGE_SIZE } = require('../constants'); | ||
const { delay } = require('../../../helpers'); | ||
|
||
const fetchDomainListNextPage = async ({ | ||
ctx, | ||
domainList = [], | ||
nextPageToken = '', | ||
}) => { | ||
const data = await ctx.cadence.listDomains({ | ||
pageSize: DOMAIN_LIST_PAGE_SIZE, | ||
nextPageToken: nextPageToken | ||
? Buffer.from(encodeURIComponent(nextPageToken), 'base64') | ||
: undefined, | ||
}); | ||
|
||
domainList.splice(domainList.length, 0, ...data.domains); | ||
|
||
if (!data.nextPageToken) { | ||
return domainList; | ||
} | ||
|
||
await delay(DOMAIN_LIST_DELAY_MS); | ||
|
||
return fetchDomainListNextPage({ | ||
ctx, | ||
nextPageToken: data.nextPageToken, | ||
domainList, | ||
}); | ||
}; | ||
|
||
module.exports = fetchDomainListNextPage; |
81 changes: 81 additions & 0 deletions
81
server/router/services/domain-service/helpers/fetch-domain-list-next-page.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
import { delay } from '../../../helpers'; | ||
import fetchDomainListNextPage from './fetch-domain-list-next-page'; | ||
|
||
jest.mock('../../../helpers', () => ({ | ||
delay: jest.fn(), | ||
})); | ||
|
||
describe('fetchDomainListNextPage', () => { | ||
const getMockContext = domainResponse => { | ||
const ctx = { | ||
cadence: { | ||
listDomains: jest.fn().mockImplementation(() => domainResponse), | ||
}, | ||
}; | ||
|
||
return ctx; | ||
}; | ||
|
||
describe('when no nextPageToken returned', () => { | ||
it('should return domainList.', async () => { | ||
const domains = ['domain1', 'domain2']; | ||
const domainResponse = { | ||
domains, | ||
}; | ||
|
||
const ctx = getMockContext(domainResponse); | ||
|
||
const domainList = await fetchDomainListNextPage({ | ||
ctx, | ||
}); | ||
|
||
expect(domainList).toEqual(domains); | ||
}); | ||
}); | ||
|
||
describe('when nextPageToken is returned', () => { | ||
it('should call delay and should call itself again to get next domain list page.', async () => { | ||
const nextPageToken = '1234'; | ||
const domains1 = ['domain1', 'domain2']; | ||
const domains2 = ['domain3', 'domain4']; | ||
const domainResponse = { | ||
domains: domains1, | ||
nextPageToken, | ||
}; | ||
|
||
const ctx = getMockContext(domainResponse); | ||
|
||
delay.mockImplementation(() => { | ||
domainResponse.domains = domains2; | ||
domainResponse.nextPageToken = null; | ||
}); | ||
|
||
const domainList = await fetchDomainListNextPage({ | ||
ctx, | ||
}); | ||
|
||
expect(domainList).toEqual([...domains1, ...domains2]); | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
server/router/services/domain-service/helpers/fetch-domain-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const fetchDomainListNextPage = require('./fetch-domain-list-next-page'); | ||
const sortDomainList = require('./sort-domain-list'); | ||
|
||
const fetchDomainList = ctx => async () => { | ||
const domainList = await fetchDomainListNextPage({ ctx }); | ||
|
||
return sortDomainList(domainList); | ||
}; | ||
|
||
module.exports = fetchDomainList; |
27 changes: 27 additions & 0 deletions
27
server/router/services/domain-service/helpers/get-domain-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const fetchDomainList = require('./fetch-domain-list'); | ||
|
||
const getDomainList = ({ cacheManager, ctx }) => | ||
cacheManager.get(fetchDomainList(ctx)); | ||
|
||
module.exports = getDomainList; |
46 changes: 46 additions & 0 deletions
46
server/router/services/domain-service/helpers/get-matching-domains.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2021 Uber Technologies Inc. | ||
// | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
const { DOMAIN_LIST_SEARCH_SIZE } = require('../constants'); | ||
|
||
const getMatchingDomains = ({ domainList, querystring }) => { | ||
if (!querystring) { | ||
return domainList.slice(0, DOMAIN_LIST_SEARCH_SIZE); | ||
} | ||
|
||
const matchedDomainList = []; | ||
|
||
for (let i = 0; i < domainList.length; i++) { | ||
if (matchedDomainList.length === DOMAIN_LIST_SEARCH_SIZE) { | ||
return matchedDomainList; | ||
} | ||
|
||
const domain = domainList[i]; | ||
|
||
if (domain.domainInfo.name.indexOf(querystring) !== -1) { | ||
matchedDomainList.push(domain); | ||
} | ||
} | ||
|
||
return matchedDomainList; | ||
}; | ||
|
||
module.exports = getMatchingDomains; |
Oops, something went wrong.