Skip to content

Commit

Permalink
renamed CUSTOM to PLUGGABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilianoSanchez committed Nov 23, 2021
1 parent 55d5366 commit b2736be
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 108 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
src/__tests__/customStorage/**/*.js
src/__tests__/pluggableStorage/**/*.js
lib/
bin/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const settings = {
},
// Mandatory: provide a valid Storage wrapper.
storage: {
type: 'CUSTOM',
type: 'PLUGGABLE',
prefix: 'storagePrefix',
wrapper: customStorage,
wrapper: storageWrapper,
},
synchronizerConfigs: {
synchronizerMode: 'MODE_RUN_ALL',
Expand Down
98 changes: 49 additions & 49 deletions e2e/synchronizer.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable no-magic-numbers */
// @ts-nocheck
import { Synchronizer } from '../src/index';
import { ICustomStorageWrapper } from '@splitsoftware/splitio-commons/src/storages/types';
import { IPluggableStorageWrapper } from '@splitsoftware/splitio-commons/src/storages/types';
import { PREFIX, REDIS_PREFIX, REDIS_URL, SERVER_MOCK_URL } from './utils/constants';
import runSDKConsumer from './utils/SDKConsumerMode';
import redisAdapterWrapper from './utils/inRedisService';
import { SynchronizerConfigs } from '../src/types';

// @ts-ignore
let _redisServer: ICustomStorageWrapper;
let _redisWrapper: IPluggableStorageWrapper;

/**
* Function to create a Synchronizer instance/task.
Expand All @@ -31,7 +31,7 @@ const createSynchronizer = () => {
events: SERVER_MOCK_URL,
},
storage: {
type: 'CUSTOM_TEST',
type: 'PLUGGABLE_TEST',
prefix: PREFIX,
// @ts-ignore
wrapper: redisAdapterWrapper({ options: { url: REDIS_URL } }),
Expand All @@ -54,23 +54,23 @@ const _redisStorage = redisAdapterWrapper({ options: { url: REDIS_URL } });
* Function to flush REDIS db from all keys related to e2e tests.
*/
const flushRedis = async () => {
const keys = await _redisServer.getKeysByPrefix(PREFIX);
const keys = await _redisWrapper.getKeysByPrefix(PREFIX);
for (let i = 0; i < keys.length; i++) {
await _redisServer.del(keys[i]);
await _redisWrapper.del(keys[i]);
}
};

describe('Synchronizer e2e tests', () => {
beforeAll(async (done) => {
_redisServer = _redisStorage;
await _redisServer.connect();
_redisWrapper = _redisStorage;
await _redisWrapper.connect();
await flushRedis();

done();
});

afterAll(async (done) => {
await _redisServer.close();
await _redisWrapper.disconnect();
done();
});

Expand All @@ -85,24 +85,24 @@ describe('Synchronizer e2e tests', () => {
});

it('saves [4] Splits as keys in Redis', async () => {
const splits = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);
const splits = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);

expect(splits).toHaveLength(4);
});

it('saves [2] Segments as keys in Redis', async () => {
const segments = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.segment.*`);
const segmentsRegistered = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.segments.*`);
const segments = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.segment.*`);
const segmentsRegistered = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.segments.*`);

expect(segments.filter(x => !x.match(/.till$/))).toHaveLength(2);
expect(segmentsRegistered).toHaveLength(1);
});

it('saves [2] Traffic Types keys', async () => {
const trafficTypes = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisServer.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisServer.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisServer.get(`${REDIS_PREFIX}.trafficType.user`);
const trafficTypes = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.user`);

expect(trafficTypes).toHaveLength(2);
expect(Number(ttAccount)).toBe(0);
Expand All @@ -117,13 +117,13 @@ describe('Synchronizer e2e tests', () => {
});

it('checks that [4] Impressions saved in Redis', async () => {
const impressions = await _redisServer.popItems(`${REDIS_PREFIX}.impressions`, 100);
const impressions = await _redisWrapper.popItems(`${REDIS_PREFIX}.impressions`, 100);

expect(impressions).toHaveLength(4);
});

it('checks that [2] Events are saved in Redis', async () => {
const events = await _redisServer.popItems(`${REDIS_PREFIX}.events`, 100);
const events = await _redisWrapper.popItems(`${REDIS_PREFIX}.events`, 100);

expect(events).toHaveLength(2);
});
Expand All @@ -140,16 +140,16 @@ describe('Synchronizer e2e tests', () => {
});

it('saves [4] Splits as keys in Redis', async () => {
const splits = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);
const splits = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);

expect(splits).toHaveLength(4);
});

it('saves [3] Traffic Types keys', async () => {
const trafficTypes = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisServer.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisServer.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisServer.get(`${REDIS_PREFIX}.trafficType.user`);
const trafficTypes = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.user`);

expect(trafficTypes).toHaveLength(2);
expect(Number(ttAccount)).toBe(2);
Expand All @@ -158,13 +158,13 @@ describe('Synchronizer e2e tests', () => {
});

it('checks that [0] Impressions are saved in Redis', async () => {
const impressions = await _redisServer.popItems(`${REDIS_PREFIX}.impressions`, 100);
const impressions = await _redisWrapper.popItems(`${REDIS_PREFIX}.impressions`, 100);

expect(impressions).toHaveLength(0);
});

it('checks that [0] Events are saved in Redis', async () => {
const events = await _redisServer.popItems(`${REDIS_PREFIX}.events`, 100);
const events = await _redisWrapper.popItems(`${REDIS_PREFIX}.events`, 100);

expect(events).toHaveLength(0);
});
Expand All @@ -188,7 +188,7 @@ describe('Synchronizer e2e tests - InMemoryOperation - only Splits & Segments mo
events: SERVER_MOCK_URL,
},
storage: {
type: 'CUSTOM_TEST',
type: 'PLUGGABLE_TEST',
prefix: PREFIX,
// @ts-ignore
wrapper: redisAdapterWrapper({ options: { url: REDIS_URL } }),
Expand All @@ -205,8 +205,8 @@ describe('Synchronizer e2e tests - InMemoryOperation - only Splits & Segments mo

beforeAll(async () => {
// @ts-ignore
_redisServer = _redisStorage;
await _redisServer.connect();
_redisWrapper = _redisStorage;
await _redisWrapper.connect();
await flushRedis();

await _synchronizer.initializeStorages();
Expand All @@ -219,31 +219,31 @@ describe('Synchronizer e2e tests - InMemoryOperation - only Splits & Segments mo
});

it('saves [4] Splits as keys in Redis', async () => {
const splits = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);
const splits = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);

// Check changeNumber(...71)
expect(splits).toHaveLength(4);
});

it('saves new changeNumber value', async () => {
const till = await _redisServer.getByPrefix(`${REDIS_PREFIX}.splits.till`);
const till = await _redisWrapper.getByPrefix(`${REDIS_PREFIX}.splits.till`);

expect(Number(till[0])).toBe(1619720346271);
});

it('saves [2] Segments as keys in Redis', async () => {
const segments = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.segment.*`);
const segmentsRegistered = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.segments.*`);
const segments = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.segment.*`);
const segmentsRegistered = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.segments.*`);

expect(segments.filter(x => !x.match(/.till$/))).toHaveLength(2);
expect(segmentsRegistered).toHaveLength(1);
});

it('saves [2] Traffic Types keys', async () => {
const trafficTypes = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisServer.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisServer.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisServer.get(`${REDIS_PREFIX}.trafficType.user`);
const trafficTypes = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.user`);

expect(trafficTypes).toHaveLength(2);
expect(Number(ttAccount)).toBe(0);
Expand All @@ -258,22 +258,22 @@ describe('Synchronizer e2e tests - InMemoryOperation - only Splits & Segments mo
});

it('runs again and saves [17] Splits as keys in Redis', async () => {
const splits = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);
const splits = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.split.*`);

expect(splits).toHaveLength(4);
});

it('saves new changeNumber value', async () => {
const till = await _redisServer.getByPrefix(`${REDIS_PREFIX}.splits.till`);
const till = await _redisWrapper.getByPrefix(`${REDIS_PREFIX}.splits.till`);

expect(Number(till[0])).toBe(1619720346272);
});

it('updates [4] Traffic Types keys\' values', async () => {
const trafficTypes = await _redisServer.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisServer.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisServer.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisServer.get(`${REDIS_PREFIX}.trafficType.user`);
const trafficTypes = await _redisWrapper.getKeysByPrefix(`${REDIS_PREFIX}.trafficType.*`);
const ttAccount = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.account`);
const ttTest = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.testTT`);
const ttUser = await _redisWrapper.get(`${REDIS_PREFIX}.trafficType.user`);

expect(trafficTypes).toHaveLength(2);
expect(Number(ttAccount)).toBe(2);
Expand All @@ -293,16 +293,16 @@ describe('Synchronizer - only Splits & Segments mode', () => {
beforeAll(async (done) => {
_synchronizer = await createSynchronizer();
// @ts-ignore
_synchronizer._settings.synchronizerConfigs.synchronizerMode = 'MODE_RUN_SPLIT_SEGMENTS';
_synchronizer.settings.synchronizerConfigs.synchronizerMode = 'MODE_RUN_SPLIT_SEGMENTS';
await _synchronizer.initializeStorages();
await _synchronizer.initializeSynchronizers();
executeSplitsAndSegmentsCallSpy = jest.spyOn(_synchronizer, 'executeSplitsAndSegments');
executeImpressionsAndEventsCallSpy = jest.spyOn(_synchronizer, 'executeImpressionsAndEvents');
await _synchronizer.execute();

// @ts-ignore
_redisServer = _redisStorage;
await _redisServer.connect();
_redisWrapper = _redisStorage;
await _redisWrapper.connect();

done();
});
Expand All @@ -316,7 +316,7 @@ describe('Synchronizer - only Splits & Segments mode', () => {
});

afterAll(async (done) => {
await _redisServer.close();
await _redisWrapper.disconnect();
done();
});
});
Expand All @@ -329,16 +329,16 @@ describe('Synchronizer - only Events & Impressions', () => {
beforeAll(async (done) => {
_synchronizer = await createSynchronizer();
// @ts-ignore
_synchronizer._settings.synchronizerConfigs.synchronizerMode = 'MODE_RUN_EVENTS_IMPRESSIONS';
_synchronizer.settings.synchronizerConfigs.synchronizerMode = 'MODE_RUN_EVENTS_IMPRESSIONS';
await _synchronizer.initializeStorages();
await _synchronizer.initializeSynchronizers();
executeSplitsAndSegmentsCallSpy = jest.spyOn(_synchronizer, 'executeSplitsAndSegments');
executeImpressionsAndEventsCallSpy = jest.spyOn(_synchronizer, 'executeImpressionsAndEvents');
await _synchronizer.execute();

// @ts-ignore
_redisServer = _redisStorage;
await _redisServer.connect();
_redisWrapper = _redisStorage;
await _redisWrapper.connect();

done();
});
Expand All @@ -352,7 +352,7 @@ describe('Synchronizer - only Events & Impressions', () => {
});

afterAll(async (done) => {
await _redisServer.close();
await _redisWrapper.disconnect();
done();
});
});
4 changes: 2 additions & 2 deletions e2e/utils/inRedisService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InRedisStorageOptions } from '@splitsoftware/splitio-commons/src/storag
* Wrapper for our RedisAdapter.
*
* @param {Object} redisOptions Redis options with the format expected at `settings.storage.options`.
* @returns {import("@splitsoftware/splitio-commons/types/storages/types").ICustomStorageWrapper} Wrapper for IORedis client.
* @returns {import("@splitsoftware/splitio-commons/types/storages/types").IPluggableStorageWrapper} Wrapper for IORedis client.
*/
function redisAdapterWrapper(redisOptions: InRedisStorageOptions) {

Expand Down Expand Up @@ -92,7 +92,7 @@ function redisAdapterWrapper(redisOptions: InRedisStorageOptions) {
});
});
},
close() {
disconnect() {
return Promise.resolve(redis && redis.disconnect()); // close the connection
},
};
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"test": "npm run test:unit && npm run test:e2e"
},
"dependencies": {
"@splitsoftware/splitio-commons": "1.0.1-rc.1",
"@splitsoftware/splitio-commons": "1.0.1-rc.2",
"dotenv": "^9.0.1",
"node-fetch": "^2.6.1",
"yargs": "^17.0.1"
Expand Down
Loading

0 comments on commit b2736be

Please sign in to comment.