From bdf7d7c45e22295692f685c0d665c7eb521cc219 Mon Sep 17 00:00:00 2001 From: Timur Bolotov Date: Thu, 6 Apr 2023 23:00:25 +0600 Subject: [PATCH 1/2] feat: implement markDead and markAlive in Connection Signed-off-by: Timur Bolotov --- lib/Connection.js | 11 +++++++++++ test/unit/connection.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/Connection.js b/lib/Connection.js index bd71d2c53..7930d6ea7 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -204,6 +204,17 @@ class Connection { this._status = status; } + markAlive() { + this._status = Connection.statuses.ALIVE; + this.deadCount = 0; + this.resurrectTimeout = 0; + } + + markDead() { + this._status = Connection.statuses.DEAD; + this.deadCount++; + } + buildRequestObject(params) { const url = this.url; const request = { diff --git a/test/unit/connection.test.js b/test/unit/connection.test.js index d9f0268db..7d0728c87 100644 --- a/test/unit/connection.test.js +++ b/test/unit/connection.test.js @@ -1116,3 +1116,28 @@ test('Abort with a slow body', (t) => { setImmediate(() => request.abort()); }); + +test('Connection markDead', (t) => { + t.plan(2); + + const connection = new Connection({ + url: new URL('http://localhost:9200'), + }); + + connection.markDead(); + t.equal(connection.status, Connection.statuses.DEAD); + t.equal(connection.deadCount, 1); +}); + +test('Connection markAlive', (t) => { + t.plan(2); + + const connection = new Connection({ + url: new URL('http://localhost:9200'), + }); + + connection.markDead(); + connection.markAlive(); + t.equal(connection.status, Connection.statuses.ALIVE); + t.equal(connection.deadCount, 0); +}); From ed055da3a38298131084b558bd72dbeaf87642a7 Mon Sep 17 00:00:00 2001 From: Timur Bolotov Date: Thu, 6 Apr 2023 23:20:15 +0600 Subject: [PATCH 2/2] chore: update changelog and user guide Signed-off-by: Timur Bolotov --- CHANGELOG.md | 1 + USER_GUIDE.md | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eac4e4bac..273176ebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Removed unnecessary `data` argument when invoking `OpenSearchClientError` ([#421](https://github.com/opensearch-project/opensearch-js/pull/421)) - Fixed typos in `ConnectionPool` ([#427](https://github.com/opensearch-project/opensearch-js/pull/427)) - Added the solution for the possible error during yarn installation on Windows OS ([#435](https://github.com/opensearch-project/opensearch-js/issues/435)) +- Added `markAlive` and `markDead` methods to `Connection` ([#477](https://github.com/opensearch-project/opensearch-js/pull/477)) ### Dependencies diff --git a/USER_GUIDE.md b/USER_GUIDE.md index d917f93f6..a4c37143a 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -11,6 +11,7 @@ - [Delete the document](#delete-the-document) - [Delete the index](#delete-the-index) - [Empty all Pool Connections](#empty-all-pool-connections) + - [Change Connection Status](#change-connection-status) ## Initializing a Client @@ -265,3 +266,13 @@ pool.empty(() => { // Do something after emptying the pool }); ``` + +## Change Connection Status + +```javascript +var connection = new Connection({ + url: new URL('http://localhost:9200'), +}); +connection.markDead(); +connection.markAlive(); +```