Commit 98d10707 authored by preetwinder's avatar preetwinder

use jio storage for ids

parent c4642dac
......@@ -18,7 +18,7 @@
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*global console, btoa, Blob*/
/*global console, btoa, Blob, indexedDB*/
/*jslint nomen: true, maxlen: 200*/
(function (window, QUnit, jIO, rJS) {
"use strict";
......@@ -28,7 +28,9 @@
ok = QUnit.ok,
stop = QUnit.stop,
start = QUnit.start,
deepEqual = QUnit.deepEqual;
deepEqual = QUnit.deepEqual,
test_signature_database = 'test_signature_storage_scenario';
rJS(window)
......@@ -61,6 +63,10 @@
type: "query",
sub_storage: {
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "nocapacity",
sub_storage: {
......@@ -368,6 +374,9 @@
.then(function () {
return jio.repair();
})
.then(function () {
return indexedDB.deleteDatabase('jio:' + test_signature_database);
})
.fail(function (error) {
console.error("---");
......
......@@ -24,7 +24,7 @@
function ListStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
this._sub_storage_index = new Set();
this._signature_storage = jIO.createJIO(spec.signature_storage);
}
ListStorage.prototype.get = function () {
......@@ -37,24 +37,30 @@
var gadget = this;
return gadget._sub_storage.post(value)
.push(function (id) {
gadget._sub_storage_index.add(id);
return id;
return gadget._signature_storage.put(id, {"id": id})
.push(function () {
return id;
});
});
};
ListStorage.prototype.put = function (id, value) {
var gadget = this;
return gadget._sub_storage.put(id, value)
.push(function (result) {
gadget._sub_storage_index.add(id);
return result;
return gadget._signature_storage.put(id, {"id": id})
.push(function () {
return result;
});
});
};
ListStorage.prototype.remove = function (id) {
var gadget = this;
return gadget._sub_storage.remove(id)
.push(function (result) {
gadget._sub_storage_index.delete(id);
return result;
return gadget._signature_storage.remove(id)
.push(function () {
return result;
});
});
};
ListStorage.prototype.getAttachment = function () {
......@@ -76,11 +82,10 @@
}
};
ListStorage.prototype.buildQuery = function () {
var rows = [], i, ids = Array.from(this._sub_storage_index);
for (i = 0; i < ids.length; i += 1) {
rows.push({id: ids[i], value: {}});
}
return rows;
return this._signature_storage.buildQuery({})
.push(function (result) {
return result;
});
};
jIO.addStorage('list', ListStorage);
......
......@@ -18,7 +18,7 @@
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*jslint nomen: true */
/*global Blob*/
/*global Blob, indexedDB*/
(function (jIO, QUnit) {
"use strict";
var test = QUnit.test,
......@@ -28,7 +28,8 @@
ok = QUnit.ok,
start = QUnit.start,
equal = QUnit.equal,
module = QUnit.module;
module = QUnit.module,
test_signature_database = 'test_signature_storage';
/////////////////////////////////////////////////////////////////
// Custom test substorage definition
......@@ -42,18 +43,24 @@
// ListStorage constructor
/////////////////////////////////////////////////////////////////
module("ListStorage.constructor");
test("create storage", function () {
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
});
equal(jio.__type, "list");
equal(jio.__storage._sub_storage.__type, "dummystorage1");
equal(jio.__storage._sub_storage_index.constructor.name, "Set");
equal(jio.__storage._signature_storage.__type, "indexeddb");
indexedDB.deleteDatabase('jio:' + test_signature_database);
});
/////////////////////////////////////////////////////////////////
......@@ -68,6 +75,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -88,6 +99,7 @@
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -102,6 +114,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -122,6 +138,7 @@
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -136,6 +153,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -149,12 +170,16 @@
jio.post({"name": "test_name"})
.then(function (result) {
equal(result, "posted");
equal(jio.__storage._sub_storage_index.has("posted"), true);
jio.__storage._signature_storage.get("posted")
.then(function (result) {
equal(result.id, "posted");
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -169,6 +194,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -182,12 +211,16 @@
jio.put("1", {"name": "test_name"})
.then(function (result) {
equal(result, "1");
equal(jio.__storage._sub_storage_index.has("1"), true);
jio.__storage._signature_storage.get("1")
.then(function (result) {
equal(result.id, "1");
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -198,10 +231,14 @@
module("ListStorage.remove");
test("remove called substorage remove", function () {
stop();
expect(5);
expect(4);
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -217,16 +254,19 @@
jio.put("1", {"name": "test_name"})
.then(function (result) {
equal(result, "1");
equal(jio.__storage._sub_storage_index.has("1"), true);
jio.remove("1")
.then(function (result) {
equal(result, "1");
equal(jio.__storage._sub_storage_index.has("1"), false);
jio.__storage._signature_storage.get("1")
.fail(function (error) {
equal(error.status_code, 404);
});
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -242,6 +282,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -262,6 +306,7 @@
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -276,6 +321,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -297,6 +346,7 @@
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -311,6 +361,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -330,6 +384,7 @@
ok(false, error);
})
.always(function () {
indexedDB.deleteDatabase('jio:' + test_signature_database);
start();
});
});
......@@ -342,6 +397,10 @@
var jio = jIO.createJIO({
type: "list",
signature_storage: {
type: "indexeddb",
database: test_signature_database
},
sub_storage: {
type: "dummystorage1"
}
......@@ -352,6 +411,8 @@
};
ok(jio.hasCapacity("list"));
indexedDB.deleteDatabase('jio:' + test_signature_database);
});
}(jIO, QUnit));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment