This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HARP-11487: Ensure DataProvider's connect and disposed are called once.
Both methods are now protected. Clients call instead register/unregister, and new DataProvider abstract class ensures connect is called on first registered client and dispose called on last unregistered client. Breaking API change: - Classes derived from DataProvider must use "extends" instead of "implements", and must call super() on constructor. - Custom Data sources using DataProvider must call register/unregister instead of connect/dispose.
- Loading branch information
1 parent
6ecdb26
commit 7828816
Showing
12 changed files
with
147 additions
and
57 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
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
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,63 @@ | ||
/* | ||
* Copyright (C) 2020 HERE Europe B.V. | ||
* Licensed under Apache 2.0, see full license in LICENSE | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// Mocha discourages using arrow functions, see https://mochajs.org/#arrow-functions | ||
|
||
import { expect } from "chai"; | ||
import * as sinon from "sinon"; | ||
|
||
import { DataProvider } from "../index"; | ||
|
||
class FakeDataProvider extends DataProvider { | ||
/** @override */ async connect() { | ||
// empty implementation | ||
} | ||
|
||
ready(): boolean { | ||
return true; | ||
} | ||
|
||
async getTile(): Promise<ArrayBufferLike | {}> { | ||
return await Promise.resolve({}); | ||
} | ||
|
||
/** @override */ dispose() { | ||
// Nothing to be done here. | ||
} | ||
} | ||
|
||
describe("DataProvider", function() { | ||
const clients = [{}, {}]; | ||
|
||
it("calls connect only on first registered client", function() { | ||
const dataProvider = new FakeDataProvider(); | ||
const connectSpy = sinon.spy(dataProvider, "connect"); | ||
|
||
dataProvider.register(clients[0]); | ||
expect(connectSpy.calledOnce).is.true; | ||
|
||
dataProvider.register(clients[0]); | ||
dataProvider.register(clients[1]); | ||
expect(connectSpy.calledOnce).is.true; | ||
}); | ||
|
||
it("calls dispose only on last unregistered client", function() { | ||
const dataProvider = new FakeDataProvider(); | ||
const disposeSpy = sinon.spy(dataProvider, "dispose"); | ||
|
||
dataProvider.register(clients[0]); | ||
dataProvider.register(clients[1]); | ||
|
||
dataProvider.unregister(clients[0]); | ||
dataProvider.unregister(clients[0]); | ||
expect(disposeSpy.called).is.false; | ||
|
||
dataProvider.unregister(clients[1]); | ||
expect(disposeSpy.calledOnce).is.true; | ||
dataProvider.unregister(clients[1]); | ||
expect(disposeSpy.calledOnce).is.true; | ||
}); | ||
}); |
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
Oops, something went wrong.