Schema Cache Improvements (#5612)
* Cache Improvements * improve tests * more tests * clean-up * test with singlecache * ensure indexes exists * remove ALL_KEYS * Add Insert Test * enableSingleSchemaCache default true * Revert "enableSingleSchemaCache default true" This reverts commit 323e7130fb8f695e3ca44ebf9b3b1d38905353da. * further optimization * refactor enforceFieldExists * coverage improvements * improve tests * remove flaky test * cleanup * Learned something new
This commit is contained in:
@@ -33,28 +33,12 @@ describe('SchemaCache', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not return all schemas after a single schema is stored', done => {
|
||||
const schemaCache = new SchemaCache(cacheController);
|
||||
const schema = {
|
||||
className: 'Class1',
|
||||
};
|
||||
schemaCache
|
||||
.setOneSchema(schema.className, schema)
|
||||
.then(() => {
|
||||
return schemaCache.getAllClasses();
|
||||
})
|
||||
.then(allSchemas => {
|
||||
expect(allSchemas).toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("doesn't persist cached data by default", done => {
|
||||
const schemaCache = new SchemaCache(cacheController);
|
||||
const schema = {
|
||||
className: 'Class1',
|
||||
};
|
||||
schemaCache.setOneSchema(schema.className, schema).then(() => {
|
||||
schemaCache.setAllClasses([schema]).then(() => {
|
||||
const anotherSchemaCache = new SchemaCache(cacheController);
|
||||
return anotherSchemaCache.getOneSchema(schema.className).then(schema => {
|
||||
expect(schema).toBeNull();
|
||||
@@ -68,7 +52,7 @@ describe('SchemaCache', () => {
|
||||
const schema = {
|
||||
className: 'Class1',
|
||||
};
|
||||
schemaCache.setOneSchema(schema.className, schema).then(() => {
|
||||
schemaCache.setAllClasses([schema]).then(() => {
|
||||
const anotherSchemaCache = new SchemaCache(cacheController, 5000, true);
|
||||
return anotherSchemaCache.getOneSchema(schema.className).then(schema => {
|
||||
expect(schema).not.toBeNull();
|
||||
@@ -76,4 +60,18 @@ describe('SchemaCache', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not store if ttl is null', async () => {
|
||||
const ttl = null;
|
||||
const schemaCache = new SchemaCache(cacheController, ttl);
|
||||
expect(await schemaCache.getAllClasses()).toBeNull();
|
||||
expect(await schemaCache.setAllClasses()).toBeNull();
|
||||
expect(await schemaCache.getOneSchema()).toBeNull();
|
||||
});
|
||||
|
||||
it('should convert string ttl to number', async () => {
|
||||
const ttl = '5000';
|
||||
const schemaCache = new SchemaCache(cacheController, ttl);
|
||||
expect(schemaCache.ttl).toBe(5000);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user