Skip to content

Commit 371ba1e

Browse files
authored
Merge pull request #172 from mustafaiman/fixHeartbeatTest
Fix heartbeat test
2 parents 245ed5b + aa592f3 commit 371ba1e

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/Util.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Long = require('long');
22
import {PagingPredicate} from './serialization/DefaultPredicates';
33
import {IterationType} from './core/Predicate';
44
import * as assert from 'assert';
5+
import {Comparator} from './core/Comparator';
56
export function assertNotNull(v: any) {
67
assert.notEqual(v, null, 'Non null value expected.');
78
}
@@ -48,9 +49,10 @@ export function getSortedQueryResultSet(list: Array<any>, predicate: PagingPredi
4849
return list;
4950
}
5051
var comparatorObject = predicate.getComparator();
51-
if (comparatorObject != null) {
52-
list.sort(comparatorObject.sort.bind(comparatorObject));
52+
if (comparatorObject == null) {
53+
comparatorObject = createComparator(predicate.getIterationType());
5354
}
55+
list.sort(comparatorObject.sort.bind(comparatorObject));
5456
var nearestAnchorEntry = (predicate == null) ? null : predicate.getNearestAnchorEntry();
5557
var nearestPage = nearestAnchorEntry[0];
5658
var page = predicate.getPage();
@@ -76,6 +78,23 @@ export function getSortedQueryResultSet(list: Array<any>, predicate: PagingPredi
7678
});
7779
}
7880

81+
function createComparator(iterationType: IterationType): Comparator {
82+
var object: Comparator = {
83+
sort: function(a: [any, any], b: [any, any]): number {
84+
return 0;
85+
}
86+
};
87+
switch (iterationType) {
88+
case IterationType.KEY:
89+
object.sort = (e1: [any, any], e2: [any, any]) => {return e1[0] < e2[0] ? -1 : +(e1[0] > e2[0]); }; break;
90+
case IterationType.ENTRY:
91+
object.sort = (e1: [any, any], e2: [any, any]) => {return e1[1] < e2[1] ? -1 : +(e1[1] > e2[1]); }; break;
92+
case IterationType.VALUE:
93+
object.sort = (e1: [any, any], e2: [any, any]) => {return e1[1] < e2[1] ? -1 : +(e1[1] > e2[1]); }; break;
94+
}
95+
return object;
96+
}
97+
7998
function setAnchor(list: Array<any>, predicate: PagingPredicate, nearestPage: number) {
8099
assert(list.length > 0);
81100
var size = list.length;

src/invocation/ClusterService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ClusterService extends EventEmitter {
158158
deferred.resolve();
159159
});
160160
}).catch((e) => {
161-
this.logger.warn('ClusterService', e);
161+
this.logger.warn('ClusterService', e.className, e);
162162
this.tryAddressIndex(index + 1, attemptLimit, attemptPeriod, deferred);
163163
});
164164
}

src/invocation/InvocationService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class Invocation {
6767
* Sends requests to appropriate nodes. Resolves waiting promises with responses.
6868
*/
6969
export class InvocationService {
70-
private correlationCounter = 0;
70+
private correlationCounter = 1;
7171
private eventHandlers: {[id: number]: Invocation} = {};
7272
private pending: {[id: number]: Invocation} = {};
7373
private client: HazelcastClient;
@@ -231,7 +231,7 @@ export class InvocationService {
231231
this.invoke(pendingInvocation);
232232
}, INVOCATION_RETRY_DELAY);
233233
} else {
234-
this.logger.error('InvocationService', 'Received exception as response', remoteException);
234+
this.logger.trace('InvocationService', 'Received exception as response', remoteException);
235235
deferred.reject(remoteException);
236236
}
237237
} else {

test/HeartbeatTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Heartbeat', function() {
4545
}).then(function() {
4646
return RC.startMember(cluster.id);
4747
}).then(function(member2) {
48-
RC.terminateMember(cluster.id, member2.uuid);
48+
simulateHeartbeatLost(client, member2.host + ':' + member2.port, 2000);
4949
}).catch(done);
5050
});
5151

0 commit comments

Comments
 (0)