2 new revisions:
Revision: 07498e560ec9
Author: gdusbabek <gdusba...@gmail.com>
Date: Fri Nov 11 07:49:04 2011
Log: Use uuid-js module. Patch by Patrick Negri (patr...@iugu.com.br)
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=07498e560ec9
Revision: 552ccdabd3b6
Author: gdusbabek <gdusba...@gmail.com>
Date: Fri Nov 11 07:51:19 2011
Log: A starting point for some robust UUID tests.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=552ccdabd3b6
==============================================================================
Revision: 07498e560ec9
Author: gdusbabek <gdusba...@gmail.com>
Date: Fri Nov 11 07:49:04 2011
Log: Use uuid-js module. Patch by Patrick Negri (patr...@iugu.com.br)
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=07498e560ec9
Deleted:
/lib/uuid.js
Modified:
/.gitignore
/lib/decoder.js
/lib/driver.js
/package.json
/test/test_decoder.js
/test/test_driver.js
=======================================
--- /lib/uuid.js Fri Oct 28 13:57:55 2011
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2011 Rackspace
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * Get your wheaties at http://www.ietf.org/rfc/rfc4122.txt
- * Right now this code doesn't distinguish between UUID types.
- **/
-
-/** @data is a stringified type 1 uuid. convert it to an array of ints. */
-function stringToBytes(data) {
- var parts = data.split('-');
- var ints = [];
- var intPos = 0;
- for (var i = 0; i < parts.length; i++) {
- for (var j = 0; j < parts[i].length; j+=2) {
- ints[intPos++] = parseInt(parts[i].substr(j, 2), 16);
- }
- }
- return ints;
-}
-
-/** @ints is an array of integers. convert to a stringified uuid. */
-function bytesToString(ints) {
- var str = '';
- var pos = 0;
- var parts = [4, 2, 2, 2, 6];
- for (var i = 0; i < parts.length; i++) {
- for (var j = 0; j < parts[i]; j++) {
- var octet = ints[pos++].toString(16);
- if (octet.length == 1) {
- octet = '0' + octet;
- }
- str += octet;
- }
- if (parts[i] !== 6) {
- str += '-';
- }
- }
- return str;
-}
-
-function byteAt(stringOrBuffer, i) {
- if (Buffer.isBuffer(stringOrBuffer)) {
- return stringOrBuffer[i];
- } else {
- return stringOrBuffer.charCodeAt(i);
- }
-}
-
-
-/** @binaryString is a string of bytes. this is how binary data comes to
us from cassandra. */
-function makeInts(binaryString) {
- var ints = [];
- for (var i = 0; i < binaryString.length; i++) {
- ints[i] = byteAt(binaryString, i);
- if (ints[i] > 255 || ints[i] < 0) {
- throw new Error('Unexpected byte in binary data.');
- }
- }
- return ints;
-}
-
-
-/**
- * fmt is either 'binary' or 'string'. 'binary' means data is a 16-byte
packed string. 'string' means data is a
- * 4-2-2-2-6 byte dash-delimted stringified uuid (e.g.:
04c3c390-65fb-11e0-0000-7fd66bb03abf).
- */
-UUID = module.exports.UUID = function(fmt, data) {
- // stored msb first. each byte is 8 bits of data. there are 16 of em.
- this.bytes = [];
- this.str = '';
-
- if (fmt === 'string') {
- this.str = data;
- this.bytes = stringToBytes(data);
- } else if (fmt === 'binary') {
- this.bytes = makeInts(data);
- this.str = bytesToString(this.bytes);
- } else {
- throw new Error('invalid format: ' + fmt);
- }
-};
-
-UUID.prototype.equals = function(uuid) {
- // todo: how do I assert uuid is a UUID?
- if (!uuid.str) {
- return false;
- } else {
- return uuid.str === this.str;
- }
-};
-
-UUID.prototype.toString = function() {
- return this.str;
-};
-
-// todo: decide what methods need to be exposed. reading/writing only
needs a constructor that works. timestamp, node
-// and clockSequence are the main ones that come to mind though.
=======================================
--- /.gitignore Mon Apr 18 14:42:41 2011
+++ /.gitignore Fri Nov 11 07:49:04 2011
@@ -4,3 +4,5 @@
*.iml
*.ipr
*.iws
+node_modules
+node_modules/*
=======================================
--- /lib/decoder.js Thu Aug 25 17:28:06 2011
+++ /lib/decoder.js Fri Nov 11 07:49:04 2011
@@ -17,7 +17,7 @@
/** [en|de]coder for cassandra types. */
var BigInteger = require('./bigint').BigInteger;
-var UUID = require('./uuid').UUID;
+var UUID = require('uuid-js');
// remember: values x such that -2^31 > x or x > 2^31-1 will make this
routine puke.
var bytesToNum = module.exports.bytesToNum = function(bytes) {
@@ -135,7 +135,7 @@
return bytesToNum(bytes);
}
} else if (className == AbstractTypes.TimeUUIDType) {
- return new UUID('binary', bytes);
+ return UUID.fromBytes(bytes);
} else {
return bytes;
}
=======================================
--- /lib/driver.js Tue Nov 8 12:33:50 2011
+++ /lib/driver.js Fri Nov 11 07:49:04 2011
@@ -108,7 +108,7 @@
CfDef = module.exports.CfDef = require('./system').CfDef;
ColumnDef = module.exports.ColumnDef = require('./system').ColumnDef;
BigInteger = module.exports.BigInteger = require('./bigint').BigInteger;
-UUID = module.exports.UUID = require('./uuid').UUID;
+UUID = module.exports.UUID = require('uuid-js');
/** make sure that err.message is set to something that makes sense. */
=======================================
--- /package.json Tue Nov 8 12:34:36 2011
+++ /package.json Fri Nov 11 07:49:04 2011
@@ -27,7 +27,8 @@
"thrift" : ">= 0.6.0-1",
"logmagic": ">= 0.1.1",
"generic-pool" : ">= 1.0.7",
- "whiskey": ">= 0.3.0"
+ "whiskey": ">= 0.3.0",
+ "uuid-js": ">= 0.5.2"
},
"devDependencies": {},
"licenses" : [
=======================================
--- /test/test_decoder.js Wed Nov 9 06:08:31 2011
+++ /test/test_decoder.js Fri Nov 11 07:49:04 2011
@@ -19,6 +19,7 @@
var BigInteger = require('../lib/bigint').BigInteger;
var bytesToBigLong = require('../lib/decoder').bytesToBigLong;
var bytesToNum = require('../lib/decoder').bytesToNum;
+var UUID = require('uuid-js');
function makeBuffer(string) {
return new Buffer(string, 'binary');
@@ -222,6 +223,7 @@
};
exports.testUUID = function(test, assert) {
+
/* from java:
ddf09190-6612-11e0-0000-fe8ebeead9f8->[221,240,145,144,102,18,17,224,0,0,254,142,190,234,217,248,]
ddf0b8a0-6612-11e0-0000-1e4e5d5425fc->[221,240,184,160,102,18,17,224,0,0,30,78,93,84,37,252,]
@@ -236,7 +238,7 @@
assert.strictEqual(strings.length, arrays.length);
for (var i = 0; i < strings.length; i++) {
- assert.deepEqual(new UUID('string', strings[i]).bytes, arrays[i]);
+ assert.deepEqual( UUID.fromURN(strings[i]), UUID.fromBytes(arrays[i])
);
}
test.finish();
};
=======================================
--- /test/test_driver.js Fri Oct 28 13:57:55 2011
+++ /test/test_driver.js Fri Nov 11 07:49:04 2011
@@ -605,8 +605,8 @@
exports.testUUID = function(test, assert) {
// make sure we're not comparing the same things.
- assert.ok(!new
UUID('string', '6f8483b0-65e0-11e0-0000-fe8ebeead9fe').equals(new
UUID('string', '6fd589e0-65e0-11e0-0000-7fd66bb03aff')));
- assert.ok(!new
UUID('string', '6fd589e0-65e0-11e0-0000-7fd66bb03aff').equals(new
UUID('string', 'fa6a8870-65fa-11e0-0000-fe8ebeead9fd')));
+
assert.ok(!UUID.fromURN('6f8483b0-65e0-11e0-0000-fe8ebeead9fe').equals(UUID.fromURN('6fd589e0-65e0-11e0-0000-7fd66bb03aff')));
+
assert.ok(!UUID.fromURN('6fd589e0-65e0-11e0-0000-7fd66bb03aff').equals(UUID.fromURN('fa6a8870-65fa-11e0-0000-fe8ebeead9fd')));
connect(function(err, con) {
if (err) {
assert.ok(false);
@@ -630,14 +630,14 @@
var row = rows[0];
assert.strictEqual(2, row.colCount());
- assert.ok(new
UUID('string', '6f8483b0-65e0-11e0-0000-fe8ebeead9fe').equals(row.cols[0].name));
- assert.ok(new
UUID('string', '6fd45160-65e0-11e0-0000-fe8ebeead9fe').equals(row.cols[0].value));
- assert.ok(new
UUID('string', '6fd589e0-65e0-11e0-0000-7fd66bb03aff').equals(row.cols[1].name));
- assert.ok(new
UUID('string', '6fd6e970-65e0-11e0-0000-fe8ebeead9fe').equals(row.cols[1].value));
-
- assert.ok(row.colHash[(new
UUID('string', '6fd589e0-65e0-11e0-0000-7fd66bb03aff'))].equals(row.cols[1].value));
+
assert.ok(UUID.fromURN('6f8483b0-65e0-11e0-0000-fe8ebeead9fe').equals(row.cols[0].name));
+
assert.ok(UUID.fromURN('6fd45160-65e0-11e0-0000-fe8ebeead9fe').equals(row.cols[0].value));
+
assert.ok(UUID.fromURN('6fd589e0-65e0-11e0-0000-7fd66bb03aff').equals(row.cols[1].name));
+
assert.ok(UUID.fromURN('6fd6e970-65e0-11e0-0000-fe8ebeead9fe').equals(row.cols[1].value));
+
+
assert.ok(row.colHash[(UUID.fromURN('6fd589e0-65e0-11e0-0000-7fd66bb03aff'))].equals(row.cols[1].value));
assert.ok(row.colHash[(row.cols[0].name)].equals(row.cols[0].value));
- assert.ok(row.colHash[(new
UUID('string', '6f8483b0-65e0-11e0-0000-fe8ebeead9fe'))].equals(row.cols[0].value));
+
assert.ok(row.colHash[(UUID.fromURN('6f8483b0-65e0-11e0-0000-fe8ebeead9fe'))].equals(row.cols[0].value));
assert.ok(row.colHash[(row.cols[1].name)].equals(row.cols[1].value));
}
test.finish();
@@ -726,7 +726,7 @@
// ev.on('cfready', function() {
//
// // insert 100 rows.
-// var con = new Connection('127.0.0.1', 9160, 'ints', null, null,
{use_bigints: true});
+// var con = new Connection('127.0.0.1', 19170, 'ints', null, null,
{use_bigints: true});
// var count = 100;
// var num = 0;
// for (var i = 0; i < count; i++) {
==============================================================================
Revision: 552ccdabd3b6
Author: gdusbabek <gdusba...@gmail.com>
Date: Fri Nov 11 07:51:19 2011
Log: A starting point for some robust UUID tests.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=552ccdabd3b6
Added:
/test/test_uuid.js
=======================================
--- /dev/null
+++ /test/test_uuid.js Fri Nov 11 07:51:19 2011
@@ -0,0 +1,31 @@
+// some tests for the uuid-js module.
+
+var UUID = require('uuid-js');
+
+exports['test_uuid_from_buffer'] = function(test, assert) {
+ var buf = new
Buffer('\u00ee\u00a1\u006c\u00c0\u00cf\u00bd\u0011\u00e0\u0017' +
+ '\u000a\u00dd\u0026\u0075\u0027\u009e\u0008', 'binary');
+ var uuid = UUID.fromBytes(buf);
+
assert.strictEqual(uuid.toString(), 'eea16cc0-cfbd-11e0-170a-dd2675279e08');
+ test.finish();
+};
+
+// this test currently doesn't work, but I'd like to see the work done in
uuid-js to make it happen. the problem is
+// that it only generates time uuids for the beginning or ending of a
specific millisecond. It should support
+// generating multiple successive UUIDs for the same millisecond for
highly concurrent applications.
+exports['test_uuid_backwards_in_time'] = function(test, assert) {
+ test.skip();
+
+ var ts = 1314735336316;
+ var uuidTs = UUID.fromTime(ts).toString();
+ // this forces the nano tracker in uuid to get set way ahead.
+ var uuidFuture = UUID.fromTime(ts + 5000).toString();
+ // we want to verify that the nanos used reflect ts and not ts+5000.
+ var uuidTsSame = UUID.fromTime(ts).toString();
+ assert.ok(uuidTs !== uuidFuture); // duh
+ assert.ok(uuidTs !== uuidTsSame); // generated from same TS after going
back in time.
+ // but time lo should definitely be the same.
+ // this test would have failed before we started using the back-in-time
reset block in UUID.nanos().
+ assert.strictEqual(uuidTs.split('-')[0], uuidTsSame.split('-')[0]);
+ test.finish();
+};