Skip to content

Commit f644ce8

Browse files
committed
Removed maxIdleSize from pool
Now it will only have maxSize.
1 parent 1c3a7a6 commit f644ce8

File tree

4 files changed

+24
-85
lines changed

4 files changed

+24
-85
lines changed

src/v1/internal/pool-config.js

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,54 +17,41 @@
1717
* limitations under the License.
1818
*/
1919

20-
const DEFAULT_SIZE = 50;
20+
const DEFAULT_MAX_SIZE = 50;
2121
const DEFAULT_ACQUISITION_TIMEOUT = 60000;
2222

2323
export default class PoolConfig {
2424

25-
constructor(maxIdleSize, maxSize, acquisitionTimeout) {
26-
this.maxIdleSize = valueOrDefault(maxIdleSize, DEFAULT_SIZE);
27-
this.maxSize = valueOrDefault(maxSize, DEFAULT_SIZE);
25+
constructor(maxSize, acquisitionTimeout) {
26+
this.maxSize = valueOrDefault(maxSize, DEFAULT_MAX_SIZE);
2827
this.acquisitionTimeout = valueOrDefault(acquisitionTimeout, DEFAULT_ACQUISITION_TIMEOUT);
2928
}
3029

3130
static defaultConfig() {
32-
return new PoolConfig(DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_ACQUISITION_TIMEOUT);
31+
return new PoolConfig(DEFAULT_MAX_SIZE, DEFAULT_ACQUISITION_TIMEOUT);
3332
}
3433

3534
static fromDriverConfig(config) {
3635
const maxIdleSizeConfigured = isConfigured(config.connectionPoolSize);
3736
const maxSizeConfigured = isConfigured(config.maxConnectionPoolSize);
3837

39-
if (maxIdleSizeConfigured) {
40-
console.warn('WARNING: neo4j-driver setting "connectionPoolSize" is deprecated, please use "maxConnectionPoolSize" instead');
41-
}
42-
43-
let maxIdleSize;
4438
let maxSize;
4539

46-
if (maxIdleSizeConfigured && maxSizeConfigured) {
47-
// both settings are configured - use configured values
48-
maxIdleSize = config.connectionPoolSize;
40+
if (maxSizeConfigured) {
41+
// correct size setting is set - use it's value
4942
maxSize = config.maxConnectionPoolSize;
50-
} else if (!maxIdleSizeConfigured && maxSizeConfigured) {
51-
// only maxSize is configured - use it's value for both
52-
maxIdleSize = config.maxConnectionPoolSize;
53-
maxSize = config.maxConnectionPoolSize;
54-
} else if (maxIdleSizeConfigured && !maxSizeConfigured) {
55-
// only maxIdleSize is configured - use it's value for both
56-
maxIdleSize = config.connectionPoolSize;
43+
} else if (maxIdleSizeConfigured) {
44+
// deprecated size setting is set - use it's value
45+
console.warn('WARNING: neo4j-driver setting "connectionPoolSize" is deprecated, please use "maxConnectionPoolSize" instead');
5746
maxSize = config.connectionPoolSize;
5847
} else {
59-
// none configured - use default values
60-
maxIdleSize = DEFAULT_SIZE;
61-
maxSize = DEFAULT_SIZE;
48+
maxSize = DEFAULT_MAX_SIZE;
6249
}
6350

6451
const acquisitionTimeoutConfigured = isConfigured(config.connectionAcquisitionTimeout);
6552
const acquisitionTimeout = acquisitionTimeoutConfigured ? config.connectionAcquisitionTimeout : DEFAULT_ACQUISITION_TIMEOUT;
6653

67-
return new PoolConfig(maxIdleSize, maxSize, acquisitionTimeout);
54+
return new PoolConfig(maxSize, acquisitionTimeout);
6855
}
6956
}
7057

@@ -77,6 +64,6 @@ function isConfigured(value) {
7764
}
7865

7966
export {
80-
DEFAULT_SIZE,
67+
DEFAULT_MAX_SIZE,
8168
DEFAULT_ACQUISITION_TIMEOUT
8269
};

src/v1/internal/pool.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class Pool {
3636
this._create = create;
3737
this._destroy = destroy;
3838
this._validate = validate;
39-
this._maxIdleSize = config.maxIdleSize;
4039
this._maxSize = config.maxSize;
4140
this._acquisitionTimeout = config.acquisitionTimeout;
4241
this._pools = {};
@@ -150,7 +149,7 @@ class Pool {
150149

151150
if (pool) {
152151
// there exist idle connections for the given key
153-
if (pool.length >= this._maxIdleSize || !this._validate(resource)) {
152+
if (!this._validate(resource)) {
154153
this._destroy(resource);
155154
} else {
156155
pool.push(resource);

test/internal/pool-config.test.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20-
import PoolConfig, {DEFAULT_ACQUISITION_TIMEOUT, DEFAULT_SIZE} from '../../src/v1/internal/pool-config';
20+
import PoolConfig, {DEFAULT_ACQUISITION_TIMEOUT, DEFAULT_MAX_SIZE} from '../../src/v1/internal/pool-config';
2121

2222
describe('PoolConfig', () => {
2323

@@ -36,39 +36,34 @@ describe('PoolConfig', () => {
3636
it('should respect zero values', () => {
3737
const config = new PoolConfig(0, 0, 0);
3838

39-
expect(config.maxIdleSize).toEqual(0);
4039
expect(config.maxSize).toEqual(0);
4140
expect(config.acquisitionTimeout).toEqual(0);
4241
});
4342

4443
it('should expose default config', () => {
4544
const config = PoolConfig.defaultConfig();
4645

47-
expect(config.maxIdleSize).toEqual(DEFAULT_SIZE);
48-
expect(config.maxSize).toEqual(DEFAULT_SIZE);
46+
expect(config.maxSize).toEqual(DEFAULT_MAX_SIZE);
4947
expect(config.acquisitionTimeout).toEqual(DEFAULT_ACQUISITION_TIMEOUT);
5048
});
5149

5250
it('should convert from empty driver config', () => {
5351
const driverConfig = {};
5452
const config = PoolConfig.fromDriverConfig(driverConfig);
5553

56-
expect(config.maxIdleSize).toEqual(DEFAULT_SIZE);
57-
expect(config.maxSize).toEqual(DEFAULT_SIZE);
54+
expect(config.maxSize).toEqual(DEFAULT_MAX_SIZE);
5855
expect(config.acquisitionTimeout).toEqual(DEFAULT_ACQUISITION_TIMEOUT);
5956
});
6057

6158
it('should convert from full driver config', () => {
6259
const driverConfig = {
63-
connectionPoolSize: 42,
64-
maxConnectionPoolSize: 4242,
65-
connectionAcquisitionTimeout: 424242
60+
maxConnectionPoolSize: 42,
61+
connectionAcquisitionTimeout: 4242
6662
};
6763
const config = PoolConfig.fromDriverConfig(driverConfig);
6864

69-
expect(config.maxIdleSize).toEqual(42);
70-
expect(config.maxSize).toEqual(4242);
71-
expect(config.acquisitionTimeout).toEqual(424242);
65+
expect(config.maxSize).toEqual(42);
66+
expect(config.acquisitionTimeout).toEqual(4242);
7267
});
7368

7469
it('should convert from driver config with both connectionPoolSize and maxConnectionPoolSize', () => {
@@ -78,7 +73,6 @@ describe('PoolConfig', () => {
7873
};
7974
const config = PoolConfig.fromDriverConfig(driverConfig);
8075

81-
expect(config.maxIdleSize).toEqual(42);
8276
expect(config.maxSize).toEqual(4242);
8377
expect(config.acquisitionTimeout).toEqual(DEFAULT_ACQUISITION_TIMEOUT);
8478
});
@@ -89,8 +83,7 @@ describe('PoolConfig', () => {
8983
};
9084
const config = PoolConfig.fromDriverConfig(driverConfig);
9185

92-
expect(config.maxIdleSize).toEqual(DEFAULT_SIZE);
93-
expect(config.maxSize).toEqual(DEFAULT_SIZE);
86+
expect(config.maxSize).toEqual(DEFAULT_MAX_SIZE);
9487
expect(config.acquisitionTimeout).toEqual(42);
9588
});
9689

@@ -100,8 +93,6 @@ describe('PoolConfig', () => {
10093
};
10194
const config = PoolConfig.fromDriverConfig(driverConfig);
10295

103-
// both connectionPoolSize and maxConnectionPoolSize should be set to the same value
104-
expect(config.maxIdleSize).toEqual(42);
10596
expect(config.maxSize).toEqual(42);
10697
expect(config.acquisitionTimeout).toEqual(DEFAULT_ACQUISITION_TIMEOUT);
10798
});
@@ -112,8 +103,6 @@ describe('PoolConfig', () => {
112103
};
113104
const config = PoolConfig.fromDriverConfig(driverConfig);
114105

115-
// both connectionPoolSize and maxConnectionPoolSize should be set to the same value
116-
expect(config.maxIdleSize).toEqual(42);
117106
expect(config.maxSize).toEqual(42);
118107
expect(config.acquisitionTimeout).toEqual(DEFAULT_ACQUISITION_TIMEOUT);
119108
});

test/internal/pool.test.js

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -104,42 +104,6 @@ describe('Pool', () => {
104104
});
105105
});
106106

107-
it('frees if pool reaches max size', (done) => {
108-
// Given a pool that tracks destroyed resources
109-
let counter = 0;
110-
let destroyed = [];
111-
const key = 'bolt://localhost:7687';
112-
const pool = new Pool(
113-
(url, release) => new Resource(url, counter++, release),
114-
resource => {
115-
destroyed.push(resource);
116-
},
117-
resource => true,
118-
new PoolConfig(2, 100, 60000)
119-
);
120-
121-
// When
122-
const p0 = pool.acquire(key);
123-
const p1 = pool.acquire(key);
124-
const p2 = pool.acquire(key);
125-
126-
// Then
127-
Promise.all([ p0, p1, p2 ]).then(values => {
128-
const r0 = values[0];
129-
const r1 = values[1];
130-
const r2 = values[2];
131-
132-
r0.close();
133-
r1.close();
134-
r2.close();
135-
136-
expect(destroyed.length).toBe(1);
137-
expect(destroyed[0].id).toBe(r2.id);
138-
139-
done();
140-
});
141-
});
142-
143107
it('frees if validate returns false', (done) => {
144108
// Given a pool that allocates
145109
let counter = 0;
@@ -151,7 +115,7 @@ describe('Pool', () => {
151115
destroyed.push(resource);
152116
},
153117
resource => false,
154-
new PoolConfig(1000, 1000, 60000)
118+
new PoolConfig(1000, 60000)
155119
);
156120

157121
// When
@@ -437,7 +401,7 @@ describe('Pool', () => {
437401
(url, release) => new Resource(url, counter++, release),
438402
resource => {},
439403
resource => true,
440-
new PoolConfig(2, 2, 5000)
404+
new PoolConfig(2, 5000)
441405
);
442406

443407
const p0 = pool.acquire(key);
@@ -467,7 +431,7 @@ describe('Pool', () => {
467431
(url, release) => new Resource(url, counter++, release),
468432
resource => {},
469433
resource => true,
470-
new PoolConfig(2, 2, 1000)
434+
new PoolConfig(2, 1000)
471435
);
472436

473437
const p0 = pool.acquire(key);

0 commit comments

Comments
 (0)