Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

[courier/fetch] decouple client & dataSource from fetch #12

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/ui/public/courier/__tests__/requestQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import expect from 'expect.js';
import sinon from 'auto-release-sinon';

import RequestQueueProv from '../_request_queue';
import SearchStrategyProv from '../fetch/strategy/search';
import DocStrategyProv from '../fetch/strategy/doc';
import EsDocStrategyProv from '../fetch_types/es_doc_strategy';
import EsSearchStrategyProv from '../fetch_types/es_search_strategy';

describe('Courier Request Queue', function () {
let docStrategy;
let requestQueue;
let searchStrategy;
let esDocStrategy;
let esSearchStrategy;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
docStrategy = Private(DocStrategyProv);
requestQueue = Private(RequestQueueProv);
searchStrategy = Private(SearchStrategyProv);
esDocStrategy = Private(EsDocStrategyProv);
esSearchStrategy = Private(EsSearchStrategyProv);
}));

class MockReq {
Expand All @@ -29,29 +29,29 @@ describe('Courier Request Queue', function () {
describe('#getStartable(strategy)', function () {
it('only returns requests that match one of the passed strategies', function () {
requestQueue.push(
new MockReq(docStrategy),
new MockReq(searchStrategy),
new MockReq(searchStrategy),
new MockReq(searchStrategy)
new MockReq(esDocStrategy),
new MockReq(esSearchStrategy),
new MockReq(esSearchStrategy),
new MockReq(esSearchStrategy)
);

expect(requestQueue.getStartable(docStrategy)).to.have.length(1);
expect(requestQueue.getStartable(searchStrategy)).to.have.length(3);
expect(requestQueue.getStartable(esDocStrategy)).to.have.length(1);
expect(requestQueue.getStartable(esSearchStrategy)).to.have.length(3);
});

it('returns all requests when no strategy passed', function () {
requestQueue.push(
new MockReq(docStrategy),
new MockReq(searchStrategy)
new MockReq(esDocStrategy),
new MockReq(esSearchStrategy)
);

expect(requestQueue.getStartable()).to.have.length(2);
});

it('returns only startable requests', function () {
requestQueue.push(
new MockReq(docStrategy, true),
new MockReq(searchStrategy, false)
new MockReq(esDocStrategy, true),
new MockReq(esSearchStrategy, false)
);

expect(requestQueue.getStartable()).to.have.length(1);
Expand All @@ -61,29 +61,29 @@ describe('Courier Request Queue', function () {
describe('#get(strategy)', function () {
it('only returns requests that match one of the passed strategies', function () {
requestQueue.push(
new MockReq(docStrategy),
new MockReq(searchStrategy),
new MockReq(searchStrategy),
new MockReq(searchStrategy)
new MockReq(esDocStrategy),
new MockReq(esSearchStrategy),
new MockReq(esSearchStrategy),
new MockReq(esSearchStrategy)
);

expect(requestQueue.get(docStrategy)).to.have.length(1);
expect(requestQueue.get(searchStrategy)).to.have.length(3);
expect(requestQueue.get(esDocStrategy)).to.have.length(1);
expect(requestQueue.get(esSearchStrategy)).to.have.length(3);
});

it('returns all requests when no strategy passed', function () {
requestQueue.push(
new MockReq(docStrategy),
new MockReq(searchStrategy)
new MockReq(esDocStrategy),
new MockReq(esSearchStrategy)
);

expect(requestQueue.get()).to.have.length(2);
});

it('returns startable and not-startable requests', function () {
requestQueue.push(
new MockReq(docStrategy, true),
new MockReq(searchStrategy, false)
new MockReq(esDocStrategy, true),
new MockReq(esSearchStrategy, false)
);

expect(requestQueue.get()).to.have.length(2);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Notifier from 'ui/notify/notifier';

import DocSourceProvider from './data_source/doc_source';
import SearchSourceProvider from './data_source/search_source';
import SearchStrategyProvider from './fetch/strategy/search';
import EsSearchStrategyProvider from './fetch_types/es_search_strategy';
import RequestQueueProvider from './_request_queue';
import ErrorHandlersProvider from './_error_handlers';
import FetchProvider from './fetch';
Expand All @@ -28,7 +28,7 @@ uiModules.get('kibana/courier')

var DocSource = Private(DocSourceProvider);
var SearchSource = Private(SearchSourceProvider);
var searchStrategy = Private(SearchStrategyProvider);
var esSearchStrategy = Private(EsSearchStrategyProvider);

var requestQueue = Private(RequestQueueProvider);
var errorHandlers = Private(ErrorHandlersProvider);
Expand Down Expand Up @@ -75,7 +75,7 @@ uiModules.get('kibana/courier')
* individual errors are routed to their respective requests.
*/
self.fetch = function () {
fetch.fetchQueued(searchStrategy).then(function () {
fetch.fetchQueued(esSearchStrategy).then(function () {
searchLooper.restart();
});
};
Expand Down
12 changes: 6 additions & 6 deletions src/ui/public/courier/data_source/doc_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import 'ui/storage';

import DocSendToEsProvider from './_doc_send_to_es';
import AbstractDataSourceProvider from './_abstract';
import DocRequestProvider from '../fetch/request/doc';
import DocStrategyProvider from '../fetch/strategy/doc';
import EsDocRequestProvider from '../fetch_types/es_doc_request';
import EsDocStrategyProvider from '../fetch_types/es_doc_strategy';

export default function DocSourceFactory(Private, Promise, es, sessionStorage) {
var sendToEs = Private(DocSendToEsProvider);
var SourceAbstract = Private(AbstractDataSourceProvider);
var DocRequest = Private(DocRequestProvider);
var docStrategy = Private(DocStrategyProvider);
var EsDocRequest = Private(EsDocRequestProvider);
var esDocStrategy = Private(EsDocStrategyProvider);

_.class(DocSource).inherits(SourceAbstract);
function DocSource(initialState) {
DocSource.Super.call(this, initialState, docStrategy);
DocSource.Super.call(this, initialState, esDocStrategy);
}

DocSource.prototype.onUpdate = SourceAbstract.prototype.onResults;
Expand All @@ -27,7 +27,7 @@ export default function DocSourceFactory(Private, Promise, es, sessionStorage) {
*****/

DocSource.prototype._createRequest = function (defer) {
return new DocRequest(this, defer);
return new EsDocRequest(this, defer);
};

/**
Expand Down
16 changes: 8 additions & 8 deletions src/ui/public/courier/data_source/search_source.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import _ from 'lodash';

import NormalizeSortRequestProvider from './_normalize_sort_request';
import rootSearchSource from './_root_search_source';
import AbstractDataSourceProvider from './_abstract';
import SearchRequestProvider from '../fetch/request/search';
import SegmentedRequestProvider from '../fetch/request/segmented';
import SearchStrategyProvider from '../fetch/strategy/search';
import EsSearchRequestProvider from '../fetch_types/es_search_request';
import EsSegmentedRequestProvider from '../fetch_types/es_segmented_request';
import EsSearchStrategyProvider from '../fetch_types/es_search_strategy';
import NormalizeSortRequestProvider from './_normalize_sort_request';

export default function SearchSourceFactory(Promise, Private) {
var SourceAbstract = Private(AbstractDataSourceProvider);
var SearchRequest = Private(SearchRequestProvider);
var SegmentedRequest = Private(SegmentedRequestProvider);
var searchStrategy = Private(SearchStrategyProvider);
var SearchRequest = Private(EsSearchRequestProvider);
var SegmentedRequest = Private(EsSegmentedRequestProvider);
var esSearchStrategy = Private(EsSearchStrategyProvider);
var normalizeSortRequest = Private(NormalizeSortRequestProvider);

_.class(SearchSource).inherits(SourceAbstract);
function SearchSource(initialState) {
SearchSource.Super.call(this, initialState, searchStrategy);
SearchSource.Super.call(this, initialState, esSearchStrategy);
}

/*****
Expand Down
20 changes: 12 additions & 8 deletions src/ui/public/courier/fetch/__tests__/fetch_these.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import sinon from 'auto-release-sinon';
import expect from 'expect.js';
import ngMock from 'ngMock';

import FetchTheseProvider from '../fetch/fetch_these';
import FetchTheseProvider from '../fetch_these';
import ContinueIncompleteProvider from '../continue_incomplete';
import CallResponseHandlersProvider from '../call_response_handlers';

describe('ui/courier/fetch/_fetch_these', () => {
describe('ui/courier - fetch_these', () => {

let Promise;
let $rootScope;
Expand All @@ -24,9 +26,8 @@ describe('ui/courier/fetch/_fetch_these', () => {
return fakeResponses;
}

PrivateProvider.swap(require('ui/courier/fetch/_call_client'), FakeResponsesProvider);
PrivateProvider.swap(require('ui/courier/fetch/_call_response_handlers'), FakeResponsesProvider);
PrivateProvider.swap(require('ui/courier/fetch/_continue_incomplete'), FakeResponsesProvider);
PrivateProvider.swap(CallResponseHandlersProvider, FakeResponsesProvider);
PrivateProvider.swap(ContinueIncompleteProvider, FakeResponsesProvider);
}));

beforeEach(ngMock.inject((Private, $injector) => {
Expand All @@ -53,7 +54,7 @@ describe('ui/courier/fetch/_fetch_these', () => {
expect(request.start.callCount).to.be(1);
expect(fakeResponses.callCount).to.be(0);
$rootScope.$apply();
expect(fakeResponses.callCount).to.be(3);
expect(fakeResponses.callCount).to.be(2);
});

it('invokes request failure handler if starting fails', () => {
Expand All @@ -77,7 +78,7 @@ describe('ui/courier/fetch/_fetch_these', () => {
expect(request.continue.callCount).to.be(1);
expect(fakeResponses.callCount).to.be(0);
$rootScope.$apply();
expect(fakeResponses.callCount).to.be(3);
expect(fakeResponses.callCount).to.be(2);
});
it('invokes request failure handler if continuing fails', () => {
request.continue = sinon.stub().returns(Promise.reject('some error'));
Expand All @@ -89,7 +90,10 @@ describe('ui/courier/fetch/_fetch_these', () => {

function mockRequest() {
return {
strategy: 'mock',
strategy: {
type: 'mock',
execute() {}
},
started: true,
aborted: false,
handleFailure: sinon.spy(),
Expand Down
125 changes: 0 additions & 125 deletions src/ui/public/courier/fetch/call_client.js

This file was deleted.

Loading