Commit 79d7f77b authored by Bryan Kaperick's avatar Bryan Kaperick

One additional invalid document name to check for and a temporary fix for...

One additional invalid document name to check for and a temporary fix for remove operations sometimes being incorrectly ordered.
parent aa6ed5aa
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
"use strict"; "use strict";
// Used to distinguish between operations done within the same millisecond // Used to distinguish between operations done within the same millisecond
var unique_timestamp = function () { var unique_timestamp = function (time) {
// XXX: replace this with UUIDStorage function call to S4() when it becomes // XXX: replace this with UUIDStorage function call to S4() when it becomes
// publicly accessible // publicly accessible
var uuid = ('0000' + Math.floor(Math.random() * 0x10000) var uuid = ('0000' + Math.floor(Math.random() * 0x10000)
.toString(16)).slice(-4), .toString(16)).slice(-4),
timestamp = Date.now().toString(); //timestamp = Date.now().toString();
timestamp = time.toString();
return timestamp + "-" + uuid; return timestamp + "-" + uuid;
}; };
...@@ -99,15 +100,19 @@ ...@@ -99,15 +100,19 @@
}; };
HistoryStorage.prototype.put = function (id, data) { HistoryStorage.prototype.put = function (id, data) {
if (data.hasOwnProperty("_timestamp")) { if (data.hasOwnProperty("_timestamp")) {
throw new jIO.util.jIOError( throw new jIO.util.jIOError(
"Document cannot have metadata attribute '_timestamp'", "Document cannot have metadata attribute '_timestamp'",
422 422
); );
} }
if (data.hasOwnProperty("_doc_id")) {
var timestamp = unique_timestamp(), throw new jIO.util.jIOError(
"Document cannot have metadata attribute '_doc_id'",
422
);
}
var timestamp = unique_timestamp(Date.now()),
metadata = { metadata = {
// XXX: remove this attribute once query can sort_on id // XXX: remove this attribute once query can sort_on id
timestamp: timestamp, timestamp: timestamp,
...@@ -124,7 +129,7 @@ ...@@ -124,7 +129,7 @@
}; };
HistoryStorage.prototype.remove = function (id) { HistoryStorage.prototype.remove = function (id) {
var timestamp = unique_timestamp(), var timestamp = unique_timestamp(Date.now() - 1),
metadata = { metadata = {
// XXX: remove this attribute once query can sort_on id // XXX: remove this attribute once query can sort_on id
timestamp: timestamp, timestamp: timestamp,
...@@ -186,7 +191,7 @@ ...@@ -186,7 +191,7 @@
}; };
HistoryStorage.prototype.putAttachment = function (id, name, blob) { HistoryStorage.prototype.putAttachment = function (id, name, blob) {
var timestamp = unique_timestamp(), var timestamp = unique_timestamp(Date.now()),
metadata = { metadata = {
// XXX: remove this attribute once query can sort_on id // XXX: remove this attribute once query can sort_on id
timestamp: timestamp, timestamp: timestamp,
...@@ -268,26 +273,7 @@ ...@@ -268,26 +273,7 @@
throw error; throw error;
}); });
} }
return substorage.get(id) return substorage.getAttachment(id, name)
.push(function (result) {
if (result.op === "putAttachment") {
return substorage.getAttachment(id, result.name);
}
throw new jIO.util.jIOError(
"HistoryStorage: cannot find object '" + id + "' (removed)",
404
);
},
function (error) {
if (error.status_code === 404 &&
error instanceof jIO.util.jIOError) {
throw new jIO.util.jIOError(
"HistoryStorage: cannot find object '" + id + "'",
404
);
}
throw error;
})
.push(undefined, function (error) { .push(undefined, function (error) {
if (error.status_code === 404 && if (error.status_code === 404 &&
error instanceof jIO.util.jIOError) { error instanceof jIO.util.jIOError) {
...@@ -302,7 +288,7 @@ ...@@ -302,7 +288,7 @@
}; };
HistoryStorage.prototype.removeAttachment = function (id, name) { HistoryStorage.prototype.removeAttachment = function (id, name) {
var timestamp = unique_timestamp(), var timestamp = unique_timestamp(Date.now()),
metadata = { metadata = {
// XXX: remove this attribute once query can sort_on id // XXX: remove this attribute once query can sort_on id
timestamp: timestamp, timestamp: timestamp,
......
...@@ -63,12 +63,13 @@ ...@@ -63,12 +63,13 @@
test("Testing proper adding/removing attachments", test("Testing proper adding/removing attachments",
function () { function () {
stop(); stop();
expect(7); expect(9);
var jio = this.jio, var jio = this.jio,
timestamps = this.jio.__storage._timestamps, timestamps = this.jio.__storage._timestamps,
blob2 = this.blob2, blob2 = this.blob2,
blob1 = this.blob1, blob1 = this.blob1,
other_blob = this.other_blob; other_blob = this.other_blob,
otherother_blob = new Blob(['abcabc']);
jio.put("doc", {title: "foo0"}) jio.put("doc", {title: "foo0"})
.push(function () { .push(function () {
...@@ -83,6 +84,16 @@ ...@@ -83,6 +84,16 @@
.push(function () { .push(function () {
return jio.putAttachment("doc", "other_attacheddata", other_blob); return jio.putAttachment("doc", "other_attacheddata", other_blob);
}) })
.push(function () {
return jio.putAttachment(
"doc",
"otherother_attacheddata",
otherother_blob
);
})
.push(function () {
return jio.removeAttachment("doc", "otherother_attacheddata");
})
.push(function () { .push(function () {
return jio.get("doc"); return jio.get("doc");
}) })
...@@ -142,6 +153,18 @@ ...@@ -142,6 +153,18 @@
"Other document successfully queried" "Other document successfully queried"
); );
}) })
.push(function () {
return jio.getAttachment("doc", "otherother_attacheddata");
})
.push(function () {
ok(false, "This query should have thrown a 404 error");
},
function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
404,
"Error if you try to get a removed attachment");
})
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
ok(false, error); ok(false, error);
...@@ -372,7 +395,7 @@ ...@@ -372,7 +395,7 @@
test("Handling bad input", test("Handling bad input",
function () { function () {
stop(); stop();
expect(2); expect(4);
var jio = this.jio, var jio = this.jio,
BADINPUT_ERRCODE = 422; BADINPUT_ERRCODE = 422;
...@@ -380,6 +403,21 @@ ...@@ -380,6 +403,21 @@
"_timestamp": 3, "_timestamp": 3,
"other_attr": "other_val" "other_attr": "other_val"
}) })
.push(function () {
ok(false, "This statement should not be reached");
}, function (error) {
ok(error instanceof jIO.util.jIOError, "Correct type of error");
deepEqual(error.status_code,
BADINPUT_ERRCODE,
"Can't save a document with a reserved keyword"
);
})
.push(function () {
return jio.put("doc", {
"_doc_id": 3,
"other_attr": "other_val"
});
})
.push(function () { .push(function () {
ok(false, "This statement should not be reached"); ok(false, "This statement should not be reached");
}, function (error) { }, function (error) {
...@@ -390,7 +428,7 @@ ...@@ -390,7 +428,7 @@
); );
}) })
.fail(function (error) { .fail(function (error) {
//console.log(error); //console.log(error);
ok(false, error); ok(false, error);
}) })
.always(function () {start(); }); .always(function () {start(); });
...@@ -467,6 +505,8 @@ ...@@ -467,6 +505,8 @@
subtitle: "s3" subtitle: "s3"
}, "Get returns latest revision"); }, "Get returns latest revision");
return jio.get(timestamps.doc[0]); return jio.get(timestamps.doc[0]);
}, function (err) {
ok(false, err);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
...@@ -481,6 +521,8 @@ ...@@ -481,6 +521,8 @@
subtitle: "s1" subtitle: "s1"
}, "Get returns second version"); }, "Get returns second version");
return jio.get(timestamps.doc[2]); return jio.get(timestamps.doc[2]);
}, function (err) {
ok(false, err);
}) })
.push(function (result) { .push(function (result) {
deepEqual(result, { deepEqual(result, {
...@@ -488,6 +530,8 @@ ...@@ -488,6 +530,8 @@
subtitle: "s2" subtitle: "s2"
}, "Get returns third version"); }, "Get returns third version");
return jio.get(timestamps.doc[3]); return jio.get(timestamps.doc[3]);
}, function (err) {
ok(false, err);
}) })
.push(function () { .push(function () {
ok(false, "This should have thrown a 404 error"); ok(false, "This should have thrown a 404 error");
......
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