Commit 6f44679d by preetwinder

reimplement repair

1 parent 9f2e7bd5
......@@ -241,6 +241,14 @@
// indexStorage2.buildQuery
/////////////////////////////////////////////////////////////////
module("indexStorage2.buildQuery", {
setup: function () {
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
return [];
};
},
teardown: function () {
deleteIndexedDB(this.jio);
}
......@@ -257,24 +265,22 @@
}
});
stop();
expect(3);
expect(2);
DummyStorage3.prototype.put = function (id) {
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return name === "list";
};
DummyStorage3.prototype.buildQuery = function (options) {
deepEqual(options, {});
return [
{id: "2", value: {}},
{id: "32", value: {}},
{id: "16", value: {}},
{id: "21", value: {}}
];
if (options.include_docs !== true) {
return [
{id: "2", value: {}},
{id: "32", value: {}},
{id: "16", value: {}},
{id: "21", value: {}}
];
}
return [];
};
RSVP.all([
......@@ -322,6 +328,9 @@
};
DummyStorage3.prototype.buildQuery = function (options) {
if (options.include_docs === true) {
return [];
}
deepEqual(options, {include_docs: false, select_list: ["a", "c"],
limit: 3, sort_on: [["a", "descending"], ["b", "ascending"]]});
return [
......@@ -463,10 +472,20 @@
deepEqual(value, {"a": "3", "b": "2"});
return id;
};
DummyStorage3.prototype.hasCapacity = function (capacity) {
return capacity === 'list';
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list');
};
DummyStorage3.prototype.buildQuery = function () {
return [{id: "32", doc: {"a": "3", "b": "2"}}];
};
DummyStorage3.prototype.buildQuery = function () {
return [{id: "32", value: {}}];
};
DummyStorage3.prototype.get = function (id) {
if (id === "32") {
return {"a": "3", "b": "2"};
}
};
DummyStorage3.prototype.buildQuery = undefined;
context.jio.put("32", {"a": "3", "b": "2"})
.then(function () {
......@@ -542,9 +561,6 @@
DummyStorage3.prototype.put = function (id) {
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list');
};
RSVP.all([
context.jio.put("1", {"a": "55", "b": "2"}),
......@@ -569,106 +585,6 @@
});
});
test("select_list option is preset", function () {
var context = this;
context.jio = jIO.createJIO({
type: "index2",
database: "index2_test",
index_keys: ["a", "b", "c"],
sub_storage: {
type: "dummystorage3"
}
});
stop();
expect(2);
DummyStorage3.prototype.put = function (id) {
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list');
};
RSVP.all([
context.jio.put("1", {"a": "55", "b": "2", "c": "try"}),
context.jio.put("2", {"a": "98", "b": "2", "c": "adverse"}),
context.jio.put("3", {"a": "75", "b": "2", "c": "invite"}),
context.jio.put("8", {"a": "43", "b": "3", "c": "absolve"}),
context.jio.put("6", {"a": "21", "b": "2", "c": "defy"}),
context.jio.put("4", {"a": "65", "b": "3", "c": "odd"})
])
.then(function () {
return context.jio.allDocs({select_list: ["a", "c"],
query: "b:2"});
})
.then(function (result) {
equal(result.data.total_rows, 4);
deepEqual(result.data.rows.sort(idCompare), [
{id: "1", value: {"a": "55", "c": "try"}},
{id: "2", value: {"a": "98", "c": "adverse"}},
{id: "3", value: {"a": "75", "c": "invite"}},
{id: "6", value: {"a": "21", "c": "defy"}}
]);
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
test("Select_list key is not present in the index", function () {
var context = this;
context.jio = jIO.createJIO({
type: "index2",
database: "index2_test",
index_keys: ["a", "c"],
sub_storage: {
type: "dummystorage3"
}
});
stop();
expect(3);
DummyStorage3.prototype.put = function (id) {
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'query') || (name === 'select');
};
DummyStorage3.prototype.buildQuery = function (options) {
deepEqual(options, {select_list: ["a", "b"], query: "a:55"});
return [
{id: "1", value: {"a": "55", "b": "2"}},
{id: "2", value: {"a": "55", "b": "5"}},
{id: "3", value: {"a": "55", "b": "1"}}
];
};
RSVP.all([
context.jio.put("1", {"a": "55", "b": "2", "c": "try"}),
context.jio.put("2", {"a": "55", "b": "5", "c": "adverse"}),
context.jio.put("3", {"a": "55", "b": "1", "c": "invite"})
])
.then(function () {
return context.jio.allDocs({select_list: ["a", "b"],
query: "a:55"});
})
.then(function (result) {
equal(result.data.total_rows, 3);
deepEqual(result.data.rows.sort(idCompare), [
{id: "1", value: {"a": "55", "b": "2"}},
{id: "2", value: {"a": "55", "b": "5"}},
{id: "3", value: {"a": "55", "b": "1"}}
]);
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
test("Index keys are modified", function () {
var context = this, dummy_data;
context.jio = jIO.createJIO({
......@@ -684,18 +600,18 @@
expect(8);
dummy_data = {
"32": {id: "32", value: {"a": "3", "b": "2", "c": "inverse"}},
"5": {id: "5", value: {"a": "6", "b": "2", "c": "strong"}},
"14": {id: "14", value: {"a": "67", "b": "3", "c": "disolve"}}
"32": {id: "32", doc: {"a": "3", "b": "2", "c": "inverse"}},
"5": {id: "5", doc: {"a": "6", "b": "2", "c": "strong"}},
"14": {id: "14", doc: {"a": "67", "b": "3", "c": "disolve"}}
};
DummyStorage3.prototype.put = function (id, value) {
dummy_data[id] = {id: id, value: value};
dummy_data[id] = {id: id, doc: value};
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list');
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
......@@ -792,6 +708,57 @@
});
});
test("Parallel operation", function () {
var context = this, other_storage, fake_data;
stop();
expect(3);
fake_data = {};
function checkConflict() {
var new_storage = jIO.createJIO({
type: "index2",
index_keys: ["a", "b"],
database: "shc",
sub_storage: {
type: "dummystorage3"
}
});
context.jio = new_storage;
return new_storage.allDocs({query: "a:55"})
.push(function (result) {
equal(result.data.rows.length, 1);
});
}
DummyStorage3.prototype.put = function (id, value) {
fake_data[id] = {id: id, doc: value};
return id;
};
DummyStorage3.prototype.buildQuery = function () {
return new RSVP.Promise(function (resolve) {
setTimeout(function () {
resolve(Object.values(fake_data));
}, 1000);
});
};
other_storage = jIO.createJIO({
type: "dummystorage3"
});
other_storage.put("42", {"a": "55", "b": "2"})
.then(function () {
return RSVP.all([checkConflict(), checkConflict(), checkConflict()]);
})
.fail(function (error) {
console.log(error);
})
.always(function () {
start();
});
});
/////////////////////////////////////////////////////////////////
// IndexStorage2.getAttachment
/////////////////////////////////////////////////////////////////
......@@ -937,6 +904,14 @@
return id;
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
return [];
};
RSVP.all([
context.jio.put("32", {"a": "894", "b": "inversion", "c": 2}),
context.jio.put("33", {"a": "65", "b": "division", "c": 4}),
......@@ -1021,6 +996,14 @@
}
};
DummyStorage3.prototype.hasCapacity = function (name) {
return (name === 'list') || (name === 'include');
};
DummyStorage3.prototype.buildQuery = function () {
return [];
};
RSVP.all([
context.jio.post({"a": "5", "b": "inversion", "c": 2}),
context.jio.post({"a": "62", "b": "division", "c": 4}),
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!