-
Notifications
You must be signed in to change notification settings - Fork 58
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
Send client state to cluster in re-connections[API-1644] #1415
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9d7aa7b
Make ReadResultSet iterable [API-1315]
harunalpak b62a77d
Make ReadResultSet iterable [API-1315]
harunalpak fab84a2
merge code
harunalpak 77fce4a
Merge branch 'hazelcast:master' into master
harunalpak 7a9cb25
Changes made according to comments on PR.[API-1315]
harunalpak 1487261
Merge remote-tracking branch 'upstream/master'
harunalpak 83646dc
Merge remote-tracking branch 'upstream/master'
harunalpak 87d711a
Send client state to cluster in re-connections [API-1644]
harunalpak 6f8a0a6
Merge remote-tracking branch 'upstream/master'
harunalpak 4033d30
Merge branch 'master' into API-1644
harunalpak 16c9820
New test added related to check InitializeClientOnCluster
harunalpak 0dd5c24
New test added
harunalpak 1f7388e
lint problem fixed
harunalpak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,9 @@ | |||||||
const { expect } = require('chai'); | ||||||||
const RC = require('../../RC'); | ||||||||
const TestUtil = require('../../../TestUtil'); | ||||||||
const sinon = require('sinon'); | ||||||||
const sandbox = sinon.createSandbox(); | ||||||||
const { ConnectionManager } = require('../../../../lib/network/ConnectionManager'); | ||||||||
|
||||||||
/** | ||||||||
* Basic tests for reconnection to cluster scenarios. | ||||||||
|
@@ -26,28 +29,6 @@ describe('ClientReconnectTest', function () { | |||||||
let cluster; | ||||||||
let client; | ||||||||
|
||||||||
/** | ||||||||
* Waits for disconnection. getMap(), map.put() messages are not retryable. If terminateMember does not | ||||||||
* close the client connection immediately it is possible for the client to realize that later when map.put | ||||||||
* or getMap invocation started. In that case, the connection will be closed with TargetDisconnectedError. | ||||||||
* Because these client messages are not retryable, the invocation will be rejected with an error, leading | ||||||||
* to flaky tests. To avoid that, this function will wait for the connections count to be zero. | ||||||||
*/ | ||||||||
const waitForDisconnection = async (client) => { | ||||||||
let getConnectionsFn; | ||||||||
if (TestUtil.isClientVersionAtLeast('4.2')) { | ||||||||
const clientRegistry = client.connectionRegistry; | ||||||||
getConnectionsFn = clientRegistry.getConnections.bind(clientRegistry); | ||||||||
} else { | ||||||||
const connManager = client.getConnectionManager(); | ||||||||
getConnectionsFn = connManager.getActiveConnections.bind(connManager); | ||||||||
} | ||||||||
|
||||||||
await TestUtil.assertTrueEventually(async () => { | ||||||||
expect(getConnectionsFn()).to.be.empty; | ||||||||
}); | ||||||||
}; | ||||||||
|
||||||||
const testFactory = new TestUtil.TestFactory(); | ||||||||
|
||||||||
beforeEach(function () { | ||||||||
|
@@ -59,6 +40,37 @@ describe('ClientReconnectTest', function () { | |||||||
await testFactory.shutdownAll(); | ||||||||
}); | ||||||||
|
||||||||
it('should send the client state to the cluster after reconnections, ' + | ||||||||
+'regardless it is connected back to possibly the same cluster with the same id or not.', async function () { | ||||||||
const fakeInitializeClientOnCluster = sandbox.replace( | ||||||||
ConnectionManager.prototype, | ||||||||
'initializeClientOnCluster', | ||||||||
sandbox.fake(ConnectionManager.prototype.initializeClientOnCluster) | ||||||||
); | ||||||||
cluster = await testFactory.createClusterForSerialTests(); | ||||||||
const member = await RC.startMember(cluster.id); | ||||||||
client = await testFactory.newHazelcastClientForSerialTests({ | ||||||||
clusterName: cluster.id, | ||||||||
properties: { | ||||||||
'hazelcast.client.heartbeat.interval': 1000, | ||||||||
'hazelcast.client.heartbeat.timeout': 3000 | ||||||||
} | ||||||||
}); | ||||||||
await RC.terminateMember(cluster.id, member.uuid); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
await TestUtil.waitForConnectionCount(client, 0); | ||||||||
await RC.startMember(cluster.id); | ||||||||
await TestUtil.waitForConnectionCount(client, 1); | ||||||||
fakeInitializeClientOnCluster.callCount.should.be.eq(1); | ||||||||
}); | ||||||||
|
||||||||
/** | ||||||||
* getMap(), map.put() messages are not retryable. If terminateMember does not | ||||||||
* close the client connection immediately it is possible for the client to realize that later when map.put | ||||||||
* or getMap invocation started. In that case, the connection will be closed with TargetDisconnectedError. | ||||||||
* Because these client messages are not retryable, the invocation will be rejected with an error, leading | ||||||||
* to flaky tests. To avoid that, we use the "TestUtil.waitForConnectionCount" function | ||||||||
* to wait for disconnection in the tests below. | ||||||||
*/ | ||||||||
it('member restarts, while map.put in progress', async function () { | ||||||||
cluster = await testFactory.createClusterForSerialTests(); | ||||||||
const member = await RC.startMember(cluster.id); | ||||||||
|
@@ -72,7 +84,7 @@ describe('ClientReconnectTest', function () { | |||||||
const map = await client.getMap('test'); | ||||||||
|
||||||||
await RC.terminateMember(cluster.id, member.uuid); | ||||||||
await waitForDisconnection(client); | ||||||||
await TestUtil.waitForConnectionCount(client, 0); | ||||||||
await RC.startMember(cluster.id); | ||||||||
|
||||||||
await map.put('testkey', 'testvalue'); | ||||||||
|
@@ -95,7 +107,7 @@ describe('ClientReconnectTest', function () { | |||||||
}); | ||||||||
const map = await client.getMap('test'); | ||||||||
await RC.terminateMember(cluster.id, member.uuid); | ||||||||
await waitForDisconnection(client); | ||||||||
await TestUtil.waitForConnectionCount(client, 0); | ||||||||
|
||||||||
const promise = map.put('testkey', 'testvalue').then(() => { | ||||||||
return map.get('testkey'); | ||||||||
|
@@ -119,7 +131,7 @@ describe('ClientReconnectTest', function () { | |||||||
} | ||||||||
}); | ||||||||
await RC.terminateMember(cluster.id, member.uuid); | ||||||||
await waitForDisconnection(client); | ||||||||
await TestUtil.waitForConnectionCount(client, 0); | ||||||||
|
||||||||
let map; | ||||||||
|
||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note: This test will probably fail in backward compatibility tests as there is no client version filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harunalpak I overlooked this, can you add a version check?