You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by bi...@apache.org on 2014/05/15 03:09:41 UTC

[07/10] [OLINGO-276] Check in the missing test source codes.

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-cache-fperf-tests.html
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-fperf-tests.html b/JSLib/tests/odata-cache-fperf-tests.html
new file mode 100644
index 0000000..3323199
--- /dev/null
+++ b/JSLib/tests/odata-cache-fperf-tests.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title>datajs.cache functional perf tests</title>
+    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
+    <meta http-equiv="cache-control" content="no-cache"/> 
+    <meta http-equiv="pragma" content="no-cache"/> 
+    <meta http-equiv="expires" content="-1"/> 
+
+    <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" type="text/css" />
+    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script>
+    <script type="text/javascript" src="common/TestSynchronizerClient.js"></script>
+    <script type="text/javascript">
+        window.TestSynchronizer.init(QUnit);
+    </script>
+    
+    <script type="text/javascript" src="../src/datajs.js"></script>
+    <script type="text/javascript" src="../src/utils.js"></script>
+    <script type="text/javascript" src="../src/xml.js"></script>
+
+    <script type="text/javascript" src="../src/odata-utils.js"></script>
+    <script type="text/javascript" src="../src/odata-handler.js"></script>
+    <script type="text/javascript" src="../src/odata-gml.js"></script>
+    <script type="text/javascript" src="../src/odata-xml.js"></script>
+    <script type="text/javascript" src="../src/odata-net.js"></script>
+    <script type="text/javascript" src="../src/odata-json-light.js"></script>
+    <script type="text/javascript" src="../src/odata-json.js"></script>
+    <script type="text/javascript" src="../src/odata-atom.js"></script>
+    <script type="text/javascript" src="../src/odata-metadata.js"></script>
+    <script type="text/javascript" src="../src/odata-batch.js"></script>
+    <script type="text/javascript" src="../src/odata.js"></script>
+
+    <script type="text/javascript" src="../src/store-dom.js"></script>
+    <script type="text/javascript" src="../src/store-indexeddb.js"></script>
+    <script type="text/javascript" src="../src/store-memory.js"></script>
+    <script type="text/javascript" src="../src/store.js"></script>
+  
+    <script type="text/javascript" src="../src/deferred.js"></script>
+    <script type="text/javascript" src="../src/cache-source.js"></script>
+    <script type="text/javascript" src="../src/cache.js"></script>
+    
+    <script type="text/javascript" src="common/CacheOracle.js"></script>  
+    <script type="text/javascript" src="common/djstest.js"></script>
+    <script type="text/javascript" src="odata-cache-fperf-tests.js"></script>  
+</head>
+<body>
+ <h1 id="qunit-header">datajs.cache functional perf tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-cache-fperf-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-fperf-tests.js b/JSLib/tests/odata-cache-fperf-tests.js
new file mode 100644
index 0000000..441022c
--- /dev/null
+++ b/JSLib/tests/odata-cache-fperf-tests.js
@@ -0,0 +1,103 @@
+/// <reference path="../src/datajs.js" />
+/// <reference path="../src/odata-utils.js" />
+/// <reference path="../src/cache.js" />
+/// <reference path="common/CacheOracle.js" />
+/// <reference path="common/djstest.js" />
+
+(function (window, undefined) {
+
+    var slowHttpClient = {
+        latency: 750,
+        provider: OData.defaultHttpClient,
+        request: function (request, success, error) {
+            setTimeout(function () {
+                slowHttpClient.provider.request(request, success, error);
+            }, slowHttpClient.latency);
+        }
+    };
+
+    var feeds = [
+        { uri: "./endpoints/FoodStoreDataServiceV4.svc/Foods" }
+    ];
+
+    module("Functional", {
+        setup: function () {
+            OData.defaultHttpClient = slowHttpClient;
+        },
+        teardown: function () {
+            OData.defaultHttpClient = slowHttpClient.provider;
+        }
+    });
+
+    var cacheReadRangeWallClockTest = function (totalReads, interval, mechanism, source, pageSize, prefetchSize, generateRange, threshold) {
+        /// <summary>Cache readRange wall-clock test</summary>
+        /// <remarks>
+        /// The average time computed by the wall-clock test does *not* include the initial readRange
+        /// </remarks>
+        /// <param name="totalReads">Number of reads to collect data from</param>
+        /// <param name="interval">Interval (milliseconds) between reads</param>
+        /// <param name="mechanism">The cache store mechanism</param>
+        /// <param name="source">The feed source</param>
+        /// <param name="pageSize">The page size</param>
+        /// <param name="prefetchSize">The prefetch size</param>
+        /// <param name="generateRange">The range generator function: given the read index, returns the readRange index and count</param>
+        /// <param name="threshold">The average read time threshold for test to pass; if not specified, defaults to the slowHttpClient latency</param>
+        /// <returns>The test function</param>
+        return function () {
+            var cache = datajs.createDataCache({ name: "cache" + new Date().valueOf(), source: source, pageSize: pageSize, prefetchSize: prefetchSize });
+            var totalTime = 0;
+            var readCount = 0;
+
+            var callReadRange = function () {
+                var range = generateRange(readCount);
+                var startTime = new Date().valueOf();
+                cache.readRange(range.index, range.count).then(function (data) {
+                    var duration = (new Date().valueOf()) - startTime;
+                    djstest.log("readRange " + readCount + " [" + range.index + ", " + range.count + "]: " + duration + "ms");
+
+                    // The first readRange is not counted
+                    totalTime += (readCount > 0) ? duration : 0;
+                    readCount += 1;
+
+                    if (readCount < totalReads) {
+                        setTimeout(callReadRange, interval);
+                    } else {
+                        // The first readRange is not counted
+                        var averageTime = totalTime / (totalReads - 1);
+                        var actualThreshold = threshold === undefined ? slowHttpClient.latency : threshold;
+                        djstest.assert(averageTime < actualThreshold, "Average: " + averageTime + "ms, Threshold: " + actualThreshold + "ms");
+                        djstest.destroyCacheAndDone(cache);
+                    }
+                }, function (err) {
+                    djstest.fail("Unexpected call to error handler with error: " + djstest.toString(err));
+                    djstest.destroyCacheAndDone(cache);
+                });
+            };
+
+            callReadRange();
+        };
+    };
+
+    $.each(CacheOracle.mechanisms, function (_, mechanism) {
+        if (mechanism !== "best" && CacheOracle.isMechanismAvailable(mechanism)) {
+            $.each(feeds, function (_, feed) {
+                djstest.addTest(cacheReadRangeWallClockTest(2, 1000, mechanism, feed.uri, 5, 0, function () {
+                    return { index: 0, count: 5 };
+                }), "Cache small single-page wall-clock test with " + mechanism + " on " + feed.uri);
+
+                djstest.addTest(cacheReadRangeWallClockTest(5, 1000, mechanism, feed.uri, 3, -1, function (readCount) {
+                    return { index: readCount * 3, count: 3 };
+                }), "Cache page-by-page wall-clock test with " + mechanism + " on " + feed.uri);
+
+                djstest.addTest(cacheReadRangeWallClockTest(5, 1000, mechanism, feed.uri, 3, -1, function (readCount) {
+                    return { index: readCount, count: 3 };
+                }), "Cache line-by-line wall-clock test with " + mechanism + " on " + feed.uri);
+            });
+
+            var largeFeedUri = "./endpoints/LargeCollectionService.svc/Customers";
+            djstest.addTest(cacheReadRangeWallClockTest(2, 1000, mechanism, largeFeedUri, 100, 0, function () {
+                return { index: 0, count: 500 };
+            }), "Cache large single-page wall-clock test with " + mechanism + " on " + largeFeedUri, undefined, 60000);
+        }
+    });
+})(this);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-cache-functional-tests.html
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-functional-tests.html b/JSLib/tests/odata-cache-functional-tests.html
new file mode 100644
index 0000000..e6f2992
--- /dev/null
+++ b/JSLib/tests/odata-cache-functional-tests.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title>OData tests against local service</title>
+    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
+    <meta http-equiv="cache-control" content="no-cache"/> 
+    <meta http-equiv="pragma" content="no-cache"/> 
+    <meta http-equiv="expires" content="-1"/> 
+
+    <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" type="text/css" />
+    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script>
+    <script type="text/javascript" src="common/TestSynchronizerClient.js"></script>
+    <script type="text/javascript">
+        window.TestSynchronizer.init(QUnit);
+    </script>
+    
+    <script type="text/javascript" src="../src/datajs.js"></script>
+    <script type="text/javascript" src="../src/utils.js"></script>
+    <script type="text/javascript" src="../src/xml.js"></script>
+
+    <script type="text/javascript" src="../src/odata-utils.js"></script>
+    <script type="text/javascript" src="../src/odata-handler.js"></script>
+    <script type="text/javascript" src="../src/odata-gml.js"></script>
+    <script type="text/javascript" src="../src/odata-xml.js"></script>
+    <script type="text/javascript" src="../src/odata-net.js"></script>
+    <script type="text/javascript" src="../src/odata-json-light.js"></script>
+    <script type="text/javascript" src="../src/odata-json.js"></script>
+    <script type="text/javascript" src="../src/odata-atom.js"></script>
+    <script type="text/javascript" src="../src/odata-metadata.js"></script>
+    <script type="text/javascript" src="../src/odata-batch.js"></script>
+    <script type="text/javascript" src="../src/odata.js"></script>
+
+    <script type="text/javascript" src="../src/store-dom.js"></script>
+    <script type="text/javascript" src="../src/store-indexeddb.js"></script>
+    <script type="text/javascript" src="../src/store-memory.js"></script>
+    <script type="text/javascript" src="../src/store.js"></script>
+  
+    <script type="text/javascript" src="../src/deferred.js"></script>
+    <script type="text/javascript" src="../src/cache-source.js"></script>
+    <script type="text/javascript" src="../src/cache.js"></script>
+    
+    <script type="text/javascript" src="common/djstest.js"></script>
+    <script type="text/javascript" src="common/CacheOracle.js"></script>
+    <script type="text/javascript" src="common/ObservableHttpClient.js"></script>
+    <script type="text/javascript" src="common/ODataReadOracle.js"></script>
+    <script type="text/javascript" src="odata-cache-functional-tests.js"></script>  
+</head>
+<body>
+ <h1 id="qunit-header">datajs.cache tests against local in-memory service</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-cache-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-functional-tests.js b/JSLib/tests/odata-cache-functional-tests.js
new file mode 100644
index 0000000..1a65c6f
--- /dev/null
+++ b/JSLib/tests/odata-cache-functional-tests.js
@@ -0,0 +1,611 @@
+/// <reference path="../src/datajs.js" />
+/// <reference path="../src/odata-utils.js" />
+/// <reference path="../src/cache.js" />
+/// <reference path="common/djstest.js" />
+
+(function (window, undefined) {
+    OData.defaultHandler.accept = "application/json;q=0.9, application/atomsvc+xml;q=0.8, */*;q=0.1";
+    var CustomDataSource = function (baseUri) {
+        this.baseUri = baseUri;
+    };
+
+    CustomDataSource.prototype.read = function (index, count, success, error) {
+        var that = this;
+        var url = this.baseUri + "?$skip=" + index + "&$top=" + count;
+        $(this).triggerHandler("request", { requestUri: url });
+        $.ajax({
+            url: url,
+            dataType: "json",
+            success: function (results) {
+                $(that).triggerHandler("success", { data: results });
+                success(results);
+            },
+            error: error
+        });
+    };
+
+    CustomDataSource.prototype.count = function (success, error) {
+        $.ajax({
+            url: "./endpoints/CustomDataService.svc/Count",
+            dataType: "json",
+            success: success,
+            error: error
+        });
+    },
+    CustomDataSource.prototype.toString = function () {
+        return this.baseUri;
+    };
+
+    var sources = [
+        { source: "./endpoints/FoodStoreDataServiceV4.svc/Foods", countSupported: true },
+        { source: new CustomDataSource("./endpoints/CustomDataService.svc/ReadRange"), countSupported: true }
+    ];
+
+    var itemsInCollection = 16;
+
+    // Cache config variations for single readRange with fixed skip/take that spans the entire collection
+    var pageSizes = [
+        1,
+        4,  // factor of total, <= server page size
+        5,  // non-factor of total, <= server page size
+        6,  // non-factor of total, > server page size
+        8,  // factor of total, > server page size
+        itemsInCollection,
+        itemsInCollection + 1
+    ];
+
+    var cacheSizes = [
+        -5,           // All you can store 
+         0,           // Store nothing
+         1024,        // 1 KB
+         2.5 * 1024,  // 2.5 KB
+         100 * 1024,  // 10 KB
+         512 * 1024,  // 512 KB
+         100 * 1024 * 1024, // 100 MB
+         undefined    // Default to 1 MB
+    ];
+
+    // Skip/take variations for single readRange with fixed cache config
+    var fixedPageSize = 6;
+
+    var skipValues = [
+        0,
+        fixedPageSize - 1,
+        fixedPageSize,
+        fixedPageSize + 1,
+        fixedPageSize * 2,
+        itemsInCollection + 1,
+        itemsInCollection + fixedPageSize + 1
+    ];
+
+    var takeValues = [
+        0,
+        fixedPageSize - 1,
+        fixedPageSize,
+        fixedPageSize + 1,
+        fixedPageSize * 2,
+        itemsInCollection + 1
+    ];
+
+    // Skip/take variations for multiple readRanges with fixed cache config
+    var multipleReads = [
+        { skip: 1, take: 2 },   // page 1
+        {skip: 2, take: 7 },   // page 1, 2
+        {skip: 3, take: 10 },  // page 1, 2, 3
+        {skip: 6, take: 2}    // page 2
+    ];
+
+    var invalidSkipValues = [-5, NaN, undefined, Infinity, "not a valid value"];
+    var invalidTakeValues = [-5, NaN, undefined, Infinity, "not a valid value"];
+    var invalidPageSizes = [-5, NaN, Infinity, 0, "not a valid value"];
+
+    // Prefetchsize variations for a single readRange
+    var prefetchSizes = [
+        -5,
+        1,
+        5,
+        itemsInCollection,
+        itemsInCollection + 1
+    ];
+
+    var expectException = function (cache) {
+        djstest.assert(false, "We should not get here because the an exception is expected.");
+        djstest.destroyCacheAndDone(cache);
+    };
+
+    var makeUnexpectedErrorHandler = function (cache) {
+        return function (err) {
+            djstest.assert(false, "Unexpected call to error handler with error: " + djstest.toString(err));
+            if (cache) {
+                djstest.destroyCacheAndDone(cache);
+            } else {
+                djstest.done();
+            }
+        };
+    };
+
+    var validateExpectedRange = function (cache, data, source, skipValue, takeValue, finished) {
+        /// <summary>Validates the data returned by readRange</summary>
+        /// <param name="cache" type="Object">The cache object</param>
+        /// <param name="data" type="Object">The data returned by the cache</param>
+        /// <param name="source" type="Object">The base URI of the feed, or the custom data source</param>
+        /// <param name="skipValue type="Integer">The skip value</param>
+        /// <param name="takeValue" type="Integer">The take value</param>
+        /// <param name="finished" type="Function">Callback function called after data is verified</param>
+        var assertData = function (expectedData) {
+            djstest.assertAreEqualDeep(data, expectedData, "Verify response data");
+            finished();
+        };
+
+        if (typeof source === "string") {
+            var expectedRangeUrl = source + "?$skip=" + skipValue + "&$top=" + takeValue;
+            window.ODataReadOracle.readJsonAcrossServerPages(expectedRangeUrl, assertData);
+        } else {
+            source.read(skipValue, takeValue, assertData);
+        }
+    };
+
+    var onidleValidation = function () {
+        djstest.assert(true, "expected call to onidle");
+        djstest.done();
+    };
+
+    var createSingleReadTestName = function (params) {
+        return "Testing readRange of " + params.source + " [skip " + params.skip + " take " + params.take + "] with pageSize " +
+            params.pageSize + ", prefetch " + params.prefetchSize + " and cacheSize " + params.cacheSize;
+    };
+
+    var createMultipleReadTestName = function (params) {
+        return "Testing readRange of " + params.source + " [skip " + params.firstSkip + " take " + params.firstTake + ", " +
+            (params.destroyCacheBetweenReads ? "cache.destroy(), " : "") +
+            "skip " + params.secondSkip + " take " + params.secondTake + "] with pageSize " +
+            params.pageSize + ", prefetch " + params.prefetchSize + " and cacheSize " + params.cacheSize;
+    };
+
+    var dataCacheSingleReadRangeTest = function (params) {
+        djstest.assertsExpected(2);
+        var options = { name: "cache" + new Date().valueOf(), source: params.source, pageSize: params.pageSize, prefetchSize: params.prefetchSize, cacheSize: params.cacheSize };
+
+        if (params.mechanism) {
+            options.mechanism = params.mechanism;
+        }
+
+        var cache = this.createAndAddCache(options);
+        var session = typeof params.source === "string" ? this.observableHttpClient.newSession() : new Session(params.source);
+        var cacheOracle = new CacheOracle(params.source, params.pageSize, itemsInCollection, params.cacheSize);
+        cache.readRange(params.skip, params.take).then(function (data) {
+            cacheOracle.verifyRequests(session.requests, session.responses, params.skip, params.take, "readRange requests");
+            validateExpectedRange(cache, data, params.source, params.skip, params.take, function () {
+                djstest.destroyCacheAndDone(cache);
+            });
+        }, makeUnexpectedErrorHandler(cache));
+    };
+
+    var dataCacheParallelReadRangeTest = function (params) {
+        djstest.assertsExpected(2);
+        var options = { name: "cache" + new Date().valueOf(), source: params.source, pageSize: params.pageSize, prefetchSize: params.prefetchSize, cacheSize: params.cacheSize };
+
+        var cache = this.createAndAddCache(options);
+
+        var firstReadRange = function (finished) {
+            cache.readRange(params.firstSkip, params.firstTake).then(function (data) {
+                validateExpectedRange(cache, data, params.source, params.firstSkip, params.firstTake, finished);
+            }, makeUnexpectedErrorHandler(cache));
+        };
+
+        var secondReadRange = function (finished) {
+            cache.readRange(params.secondSkip, params.secondTake).then(function (data) {
+                validateExpectedRange(cache, data, params.source, params.secondSkip, params.secondTake, finished);
+            }, makeUnexpectedErrorHandler(cache));
+        };
+
+        djstest.asyncDo([firstReadRange, secondReadRange], function () {
+            djstest.destroyCacheAndDone(cache);
+        });
+    };
+
+    var dataCacheSerialReadRangeTest = function (params) {
+        djstest.assertsExpected(4);
+        var options = { name: "cache" + new Date().valueOf(), source: params.source, pageSize: params.pageSize, prefetchSize: params.prefetchSize, cacheSize: params.cacheSize };
+
+        var cacheOracle = new CacheOracle(params.source, params.pageSize, itemsInCollection, params.cacheSize);
+        var secondRead = function () {
+            session.clear();
+            cache.readRange(params.secondSkip, params.secondTake).then(function (data) {
+                cacheOracle.verifyRequests(session.requests, session.responses, params.secondSkip, params.secondTake, "Second readRange requests");
+                validateExpectedRange(cache, data, params.source, params.secondSkip, params.secondTake, djstest.done);
+            }, makeUnexpectedErrorHandler(cache));
+        };
+
+        var cache = this.createAndAddCache(options);
+        var session = typeof params.source === "string" ? this.observableHttpClient.newSession() : new Session(params.source);
+        cache.readRange(params.firstSkip, params.firstTake).then(function (data) {
+            cacheOracle.verifyRequests(session.requests, session.responses, params.firstSkip, params.firstTake, "First readRange requests");
+            validateExpectedRange(cache, data, params.source, params.firstSkip, params.firstTake, function () {
+                if (params.destroyCacheBetweenReads === true) {
+                    cache.clear().then(function () {
+                        cacheOracle.clear();
+                        secondRead();
+                    }, function (err) {
+                        djstest.fail("Error destroying the cache: " + djstest.toString(err));
+                    });
+                } else {
+                    secondRead();
+                }
+            });
+        }, makeUnexpectedErrorHandler(cache));
+    };
+
+    var dataCachePrefetchTest = function (params) {
+        djstest.assertsExpected(2);
+        var options = {
+            name: "cache" + new Date().valueOf(),
+            source: params.source,
+            pageSize: params.pageSize,
+            prefetchSize: params.prefetchSize,
+            cacheSize: params.cacheSize,
+            user: params.user,
+            password: params.password
+        };
+
+        var cache = this.createAndAddCache(options);
+        var session = typeof params.source === "string" ? this.observableHttpClient.newSession() : new Session(params.source);
+        var cacheOracle = new CacheOracle(params.source, params.pageSize, itemsInCollection, params.cacheSize);
+
+        cache.readRange(params.skip, params.take).then(function (data) {
+            cacheOracle.verifyRequests(session.requests, session.responses, params.skip, params.take, "readRange requests");
+            session.clear();
+        }, makeUnexpectedErrorHandler(cache));
+
+        cache.onidle = function () {
+            var prefetchSize = params.prefetchSize < 0 ? itemsInCollection : params.prefetchSize;
+            cacheOracle.verifyRequests(session.requests, session.responses, params.skip + params.take, prefetchSize, "prefetch requests", false, true);
+            cache.onidle = false;
+            djstest.destroyCacheAndDone(cache);
+        };
+    };
+
+    var cleanDomStorage = function (done) {
+        /// <summary>Cleans all the data saved in the browser's DOM Storage. Needs to be called asynchronously in the 
+        /// setup and teardown methods to be consistent with indexedDb's cleanup method.</summary>
+        /// <param name="done" type="Function">Function to be called after DOM storage is cleared.</param>
+        if (window.localStorage) {
+            window.localStorage.clear();
+        }
+        done();
+    };
+
+    var cleanIndexedDb = function (done) {
+        /// <summary>Cleans all the data saved in the browser's IndexedDb Storage.</summary>
+        /// <param name="done" type="Function">Function to be called after indexedDb is cleared.</param>
+        var caches = this.caches;
+
+        djstest.cleanStoreOnIndexedDb(caches, done);
+    };
+
+    var cleanupAllStorage = function (done) {
+        /// <summary>Cleans up all available storage mechanisms in the browser.</summary>
+        /// <param name="done" type="Function">Function to be called by each cleanup function after storage is cleared.</param>
+        var that = this;
+        var storeCleanup = [];
+
+        $.each(CacheOracle.mechanisms, function (_, mechanism) {
+            if (CacheOracle.isMechanismAvailable(mechanism)) {
+                storeCleanup.push(function (done) {
+                    if (storageMechanisms[mechanism]) {
+                        storageMechanisms[mechanism].cleanup.call(that, done);
+                    } else {
+                        done();
+                    }
+                });
+            }
+        });
+
+        djstest.asyncDo(storeCleanup, done);
+    };
+
+    var storageMechanisms = {
+        indexeddb: { cleanup: cleanIndexedDb },
+        dom: { cleanup: cleanDomStorage },
+        memory: { cleanup: function (done) { done(); } },
+        best: { cleanup: function (done) { done(); } }
+    };
+
+    module("Functional", {
+        setup: function () {
+            this.createAndAddCache = function (options) {
+                /// <summary>Returns a cache created from the options object and </summary>
+                /// <param name="options" type="Object">Object to create a cache from.</param> 
+                var cache = datajs.createDataCache(options);
+                this.caches.push({ name: options.name, cache: cache });
+                return cache;
+            };
+
+            this.observableHttpClient = new ObservableHttpClient();
+            OData.defaultHttpClient = this.observableHttpClient;
+            this.caches = [];
+            var that = this;
+
+            djstest.wait(function (done) {
+                cleanupAllStorage.call(that, done);
+            });
+        },
+
+        teardown: function () {
+            OData.defaultHttpClient = this.observableHttpClient.provider;
+            var clearActions = [];
+            var that = this;
+
+            $.each(this.caches, function (_, cacheObject) {
+                cacheObject.cache.onidle = undefined;
+
+                clearActions.push(function (done) {
+                    cacheObject.cache.clear().then(function () {
+                        done();
+                    },
+                        function (err) {
+                            djstest.assert(false, "Unexpected call to error handler while attempting to clear with error: " + djstest.toString(err));
+                        })
+                });
+            });
+
+            djstest.wait(function (done) {
+                djstest.asyncDo(clearActions, function () {
+                    cleanupAllStorage.call(that, function () {
+                        that.caches = [];
+                        done();
+                    });
+                });
+            });
+        }
+    });
+
+    $.each(CacheOracle.mechanisms, function (_, mechanism) {
+        var parameters = { mechanism: mechanism, source: sources[1].source, take: 5, skip: 0, pageSize: 5, prefetchSize: 5 };
+        if (CacheOracle.isMechanismAvailable(mechanism)) {
+            djstest.addTest(dataCacheSingleReadRangeTest, "Specified mechanism: " + parameters.mechanism + createSingleReadTestName(parameters), parameters);
+        }
+        else {
+            djstest.addTest(function (params) {
+                djstest.assertsExpected(1);
+                var options = { name: "cache" + new Date().valueOf(), mechanism: params.mechanism, source: params.source };
+                try {
+                    var cache = this.createAndAddCache(options);
+                    expectException(cache);
+                }
+                catch (e) {
+                    if (mechanism === "indexeddb") {
+                        djstest.assertAreEqual(e.message, "IndexedDB is not supported on this browser", "Validating expected error");
+                    } else if (mechanism === "dom") {
+                        djstest.assertAreEqual(e.message, "Web Storage not supported by the browser", "Validating expected error");
+                    } else {
+                        djstest.fail("Creating cache with mechanism " + mechanism + " should not fail: " + djstest.toString(e));
+                    }
+
+                    djstest.done();
+                }
+            }, "Invalid mechanism for browser: " + parameters.mechanism + createSingleReadTestName(parameters), parameters);
+        }
+    });
+
+    $.each(sources, function (_, sourceObject) {
+        $.each(pageSizes, function (_, pageSizeValue) {
+            $.each(cacheSizes, function (_, cacheSizeValue) {
+                var parameters = { source: sourceObject.source, skip: 0, take: itemsInCollection, pageSize: pageSizeValue, prefetchSize: 0, cacheSize: cacheSizeValue };
+                djstest.addTest(dataCacheSingleReadRangeTest, createSingleReadTestName(parameters), parameters);
+            });
+        });
+
+        $.each(skipValues, function (_, skipValue) {
+            $.each(takeValues, function (_, takeValue) {
+                var parameters = { source: sourceObject.source, take: takeValue, skip: skipValue, pageSize: 4, prefetchSize: 0, cacheSize: 0 };
+                djstest.addTest(dataCacheSingleReadRangeTest, createSingleReadTestName(parameters), parameters);
+            });
+        });
+
+        $.each(multipleReads, function (_, firstRange) {
+            $.each(multipleReads, function (_, secondRange) {
+                var parallelReadParams = { source: sourceObject.source, firstTake: firstRange.take, firstSkip: firstRange.skip, secondTake: secondRange.take, secondSkip: secondRange.skip, pageSize: 5, prefetchSize: 0, cacheSize: 0 };
+                djstest.addTest(dataCacheParallelReadRangeTest, "Parallel: " + createMultipleReadTestName(parallelReadParams), parallelReadParams);
+
+                $.each([false, true], function (_, destroyCacheBetweenReads) {
+                    var serialReadParams = $.extend({}, parallelReadParams, { destroyCacheBetweenReads: destroyCacheBetweenReads });
+                    djstest.addTest(dataCacheSerialReadRangeTest, "Serial: " + createMultipleReadTestName(serialReadParams), serialReadParams);
+                });
+            });
+        });
+
+        var getInvalidValueErrorMessage = function (invalidValue, parameterName) {
+            /// <summary>Returns the expected error message for the specified invalid value.</summary>
+            /// <param name="invalidValue type="Object">invalid value (anything other than zero or positive integer) to determine the error message from.</param>
+            /// <param name="parameterName" type="String">The name of the parameter being verified.</param>
+            /// <returns type="String">Error message expected.</returns>
+            return (invalidValue === undefined || typeof invalidValue !== "number") ?
+                        "'" + parameterName + "' must be a number." :
+                        "'" + parameterName + "' must be greater than or equal to zero.";
+        };
+
+        $.each(invalidSkipValues, function (_, invalidSkipValue) {
+            var parameters = { source: sourceObject.source, skip: invalidSkipValue, take: 1 };
+            djstest.addTest(function (params) {
+                djstest.assertsExpected(1);
+                var options = { name: "cache" + new Date().valueOf(), source: params.source };
+                var cache = this.createAndAddCache(options);
+                try {
+                    cache.readRange(params.skip, params.take);
+                    expectException(cache);
+                } catch (e) {
+                    djstest.assertAreEqual(e.message, getInvalidValueErrorMessage(invalidSkipValue, "index"), "Error message validation");
+                    djstest.destroyCacheAndDone(cache);
+                }
+            }, "Invalid skip: " + createSingleReadTestName(parameters), parameters);
+        });
+
+        $.each(invalidTakeValues, function (_, invalidTakeValue) {
+            var parameters = { source: sourceObject.source, skip: 0, take: invalidTakeValue };
+            djstest.addTest(function (params) {
+                djstest.assertsExpected(1);
+                var options = { name: "cache" + new Date().valueOf(), source: params.source };
+                var cache = this.createAndAddCache(options);
+                try {
+                    cache.readRange(params.skip, params.take);
+                    expectException(cache);
+                } catch (e) {
+                    djstest.assertAreEqual(e.message, getInvalidValueErrorMessage(invalidTakeValue, "count"), "Error message validation");
+                    djstest.destroyCacheAndDone(cache);
+                }
+            }, "Invalid take: " + createSingleReadTestName(parameters), parameters);
+        });
+
+        $.each(invalidPageSizes, function (_, invalidPageSize) {
+            var parameters = { source: sourceObject.source, skip: 0, take: 5, pageSize: invalidPageSize };
+            djstest.addTest(function (params) {
+                var options = { name: "cache", source: params.source, pageSize: params.pageSize };
+                try {
+                    var cache = this.createAndAddCache(options);
+                    expectException(cache);
+                } catch (e) {
+                    var expectedError = typeof invalidPageSize === "number" ? "'pageSize' must be greater than zero." : getInvalidValueErrorMessage(invalidPageSize, "pageSize");
+                    djstest.assertAreEqual(e.message, expectedError, "Error message validation");
+                }
+                djstest.done();
+            }, "Invalid pageSize: " + createSingleReadTestName(parameters), parameters);
+        });
+
+        $.each(pageSizes, function (_, pageSize) {
+            $.each(cacheSizes, function (_, cacheSize) {
+                var parameters = { source: sourceObject.source, skip: 0, take: pageSize, pageSize: pageSize, prefetchSize: -1, cacheSize: cacheSize };
+                djstest.addTest(dataCachePrefetchTest, "Prefetch: " + createSingleReadTestName(parameters), parameters);
+            });
+        });
+
+        $.each(skipValues, function (_, skipValue) {
+            var parameters = { source: sourceObject.source, skip: skipValue, take: fixedPageSize, pageSize: fixedPageSize, prefetchSize: -1, cacheSize: -1 };
+            djstest.addTest(dataCachePrefetchTest, "Prefetch: " + createSingleReadTestName(parameters), parameters);
+        });
+
+        $.each(takeValues, function (_, takeValue) {
+            var parameters = { source: sourceObject.source, skip: 0, take: takeValue, pageSize: fixedPageSize, prefetchSize: -1, cacheSize: -1 };
+            djstest.addTest(dataCachePrefetchTest, "Prefetch: " + createSingleReadTestName(parameters), parameters);
+        });
+
+        $.each(prefetchSizes, function (_, prefetchSize) {
+            var parameters = { source: sourceObject.source, skip: 0, take: fixedPageSize, pageSize: fixedPageSize, prefetchSize: prefetchSize, cacheSize: -1 };
+            djstest.addTest(dataCachePrefetchTest, "Prefetch: " + createSingleReadTestName(parameters), parameters);
+        });
+
+        var fixedPrefetchSize = 5;
+
+        djstest.addTest(function (params) {
+            djstest.assertsExpected(1);
+            var cache = this.createAndAddCache({
+                name: "cache" + new Date().valueOf(),
+                source: params.source,
+                prefetchSize: fixedPrefetchSize,
+                idle: onidleValidation,
+                pageSize: 2,
+                mechanism: "memory"
+            });
+            cache.readRange(0, 5);
+
+        }, "onidle in constructor, prefetch size = " + fixedPrefetchSize + " on " + sourceObject.source, { source: sourceObject.source });
+
+        djstest.addTest(function (params) {
+            djstest.assertsExpected(1);
+            var cache = this.createAndAddCache({
+                name: "cache" + new Date().valueOf(),
+                source: params.source,
+                prefetchSize: fixedPrefetchSize,
+                pageSize: 2,
+                mechanism: "memory"
+            });
+            cache.onidle = onidleValidation;
+            cache.readRange(0, 5);
+        }, "onidle, prefetch size = " + fixedPrefetchSize + " on " + sourceObject.source, { source: sourceObject.source });
+
+        djstest.addTest(function (params) {
+            djstest.assertsExpected(1);
+            var cache = this.createAndAddCache({
+                name: "cache" + new Date().valueOf(),
+                source: params.source,
+                prefetchSize: fixedPrefetchSize,
+                idle: function () { djstest.assert(false, "unexpected onidle call") },
+                pageSize: 2,
+                mechanism: "memory"
+            });
+            cache.onidle = onidleValidation;
+            cache.readRange(0, 5);
+        }, "onidle override, prefetch size = " + fixedPrefetchSize + " on " + sourceObject.source, { source: sourceObject.source });
+
+        djstest.addTest(function (params) {
+            var cache = this.createAndAddCache({ name: "cache" + new Date().valueOf(), source: params.source, pageSize: 1, prefetchSize: -1 });
+            var observableSource = typeof params.source === "string" ? this.observableHttpClient : params.source;
+            cache.readRange(0, 1).then(function (data) {
+                // Let one prefetch request go out, to make sure the prefetcher is started, and then destroy the cache
+                $(observableSource).one("success", function () {
+                    var session = new Session(observableSource);
+                    cache.clear().then(function () {
+                        setTimeout(function () {
+                            djstest.assertAreEqualDeep(session.requests, [], "Verify no prefetch requests are sent out after cache.clear() callback");
+                            djstest.done();
+                        }, 1000);
+                    }, function (err) {
+                        djstest.fail("Error destroying the cache: " + djstest.toString(err));
+                    });
+                });
+            });
+        }, "Testing cache.clear() halts the prefetcher" + sourceObject.source, { source: sourceObject.source });
+
+        djstest.addTest(function (params) {
+            var cache = this.createAndAddCache({ name: "cache" + new Date().valueOf(), source: params.source });
+            if (params.countSupported) {
+                cache.count().then(function (count) {
+                    djstest.assertAreEqual(count, itemsInCollection, "All items accounted for");
+                    djstest.destroyCacheAndDone(cache);
+                }, makeUnexpectedErrorHandler(cache));
+            }
+            else {
+                cache.count().then(function (count) {
+                    djstest.assert(false, "Success should not be called, count not supported");
+                    djstest.destroyCacheAndDone(cache);
+                }, function (err) {
+                    djstest.assertAreEqual(err.message, "HTTP request failed", "Validating expected error");
+                    djstest.destroyCacheAndDone(cache);
+                });
+            }
+        }, "Testing cache.count() on " + sourceObject.source, { source: sourceObject.source, countSupported: sourceObject.countSupported });
+
+        djstest.addTest(function (params) {
+            var cache = this.createAndAddCache({ name: "cache" + new Date().valueOf(), source: params.source, pageSize: 1, prefetchSize: 0 });
+            var session = typeof params.source === "string" ? this.observableHttpClient.newSession() : new Session(params.source);
+            cache.readRange(0, 1).cancel();
+            setTimeout(function () {
+                djstest.assertAreEqualDeep(session.requests, [], "Verify no requests are sent out after readRange is cancelled");
+                djstest.done();
+            }, 1000);
+        }, "Testing cancel()" + sourceObject.source, { source: sourceObject.source });
+
+        djstest.addTest(function (params) {
+            djstest.assertsExpected(1);
+            var cache = this.createAndAddCache({ name: "cache" + new Date().valueOf(), source: params.source, pageSize: 1, prefetchSize: 0 });
+            cache.clear().then(function () {
+                cache.clear().then(function () {
+                    djstest.pass("Second clear succeeded");
+                    djstest.done();
+                }, makeUnexpectedErrorHandler(cache));
+            }, makeUnexpectedErrorHandler(cache));
+        }, "Testing .clear().then(cache.clear())" + sourceObject.source, { source: sourceObject.source });
+    });
+
+    var params = {
+        source: "./endpoints/BasicAuthDataService.svc/Customers",
+        skip: 0,
+        take: 5,
+        pageSize: 5,
+        prefetchSize: -1,
+        cacheSize: -1,
+        user: "djsUser",
+        password: "djsPassword"
+    };
+    djstest.addTest(dataCachePrefetchTest, createSingleReadTestName(params), params);
+})(this);

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-cache-rx-functional-tests.html
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-rx-functional-tests.html b/JSLib/tests/odata-cache-rx-functional-tests.html
new file mode 100644
index 0000000..8635ec3
--- /dev/null
+++ b/JSLib/tests/odata-cache-rx-functional-tests.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title>>datajs.cache toObservable() tests</title>
+    <meta http-equiv="cache-control" content="no-cache"/> 
+    <meta http-equiv="pragma" content="no-cache"/> 
+    <meta http-equiv="expires" content="-1"/> 
+
+    <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.10.0.css" type="text/css" />
+    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script>
+    <script type="text/javascript" src="common/TestSynchronizerClient.js"></script>
+    <script type="text/javascript">
+        window.TestSynchronizer.init(QUnit);
+    </script>
+    
+    <script type="text/javascript" src="../src/datajs.js"></script>
+    <script type="text/javascript" src="../src/utils.js"></script>
+    <script type="text/javascript" src="../src/xml.js"></script>
+
+    <script type="text/javascript" src="../src/odata-utils.js"></script>
+    <script type="text/javascript" src="../src/odata-handler.js"></script>
+    <script type="text/javascript" src="../src/odata-gml.js"></script>
+    <script type="text/javascript" src="../src/odata-xml.js"></script>
+    <script type="text/javascript" src="../src/odata-net.js"></script>
+    <script type="text/javascript" src="../src/odata-json-light.js"></script>
+    <script type="text/javascript" src="../src/odata-json.js"></script>
+    <script type="text/javascript" src="../src/odata-atom.js"></script>
+    <script type="text/javascript" src="../src/odata-metadata.js"></script>
+    <script type="text/javascript" src="../src/odata-batch.js"></script>
+    <script type="text/javascript" src="../src/odata.js"></script>
+
+    <script type="text/javascript" src="../src/store-dom.js"></script>
+    <script type="text/javascript" src="../src/store-indexeddb.js"></script>
+    <script type="text/javascript" src="../src/store-memory.js"></script>
+    <script type="text/javascript" src="../src/store.js"></script>
+  
+    <script type="text/javascript" src="../src/deferred.js"></script>
+    <script type="text/javascript" src="../src/cache-source.js"></script>
+    <script type="text/javascript" src="../src/cache.js"></script>
+    
+    <script type="text/javascript" src="common/djstest.js"></script>
+    <script type="text/javascript" src="common/ODataReadOracle.js"></script>
+    <script type="text/javascript" src="common/rx.js"></script>
+    <script type="text/javascript" src="odata-cache-rx-functional-tests.js"></script>  
+</head>
+<body>
+ <h1 id="qunit-header">datajs.cache toObservable() tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-cache-rx-functional-tests.js
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-cache-rx-functional-tests.js b/JSLib/tests/odata-cache-rx-functional-tests.js
new file mode 100644
index 0000000..cb47982
--- /dev/null
+++ b/JSLib/tests/odata-cache-rx-functional-tests.js
@@ -0,0 +1,74 @@
+/// <reference path="../src/datajs.js" />
+/// <reference path="../src/odata-utils.js" />
+/// <reference path="../src/cache.js" />
+/// <reference path="common/djstest.js" />
+/// <reference path="common/ODataReadOracle.js" />
+/// <reference path="common/rx.js" />
+
+(function (window, undefined) {
+    OData.defaultHandler.accept = "application/json;q=0.9, application/atomsvc+xml;q=0.8, */*;q=0.1";
+    var feeds = [
+        { uri: "./endpoints/FoodStoreDataServiceV4.svc/Foods" }
+    ];
+
+    var itemsInCollection = 16;
+    var pageSizes = [
+        1,
+        4,  // factor of total, <= server page size
+        5,  // non-factor of total, <= server page size
+        6,  // non-factor of total, > server page size
+        8,  // factor of total, > server page size
+        itemsInCollection,
+        itemsInCollection + 1
+    ];
+
+    var operatorTests = [
+        function (observable) { return observable.Take(0); },
+        function (observable) { return observable.Take(1); },
+        function (observable) { return observable.Skip(1); },
+        function (observable) { return observable.Skip(2).Take(4); },
+        function (observable) { return observable.Select(function (item) { return item.Name; }); },
+        function (observable) { return observable.Where(function (item) { return item.FoodID % 2 === 1; }); }
+    ];
+
+    var assertObservables = function (actual, expected, done) {
+        /// <summary>Asserts two finite observables generate the same sequence</summary>
+        /// <param name="actual" type="IObservable">The actual observable</param>
+        /// <param name="expected" type="IObservable">The expected observable</param>
+        /// <param name="done" type="Function">The callback function when asserts are done</param>
+        var toArray = function (observable, callback) {
+            var arr = [];
+            observable.Subscribe(
+                function (item) { arr.push(item); },
+                function (err) { arr.push({ "__error__": err }); },
+                function () { callback(arr); });
+        };
+
+        toArray(actual, function (actualSequence) {
+            toArray(expected, function (expectedSequence) {
+                djstest.assertAreEqualDeep(actualSequence, expectedSequence, "Verify observable sequence");
+                done();
+            });
+        });
+    };
+
+    module("Functional");
+    $.each(feeds, function (_, feed) {
+        $.each(pageSizes, function (_, pageSize) {
+            $.each(operatorTests, function (_, operator) {
+                var params = { feedUri: feed.uri, pageSize: pageSize, operator: operator };
+                djstest.addTest(function (params) {
+                    djstest.assertsExpected(1);
+                    var options = { name: "cache" + new Date().valueOf(), source: params.feedUri, pageSize: params.pageSize, prefetchSize: 0 };
+                    var cache = datajs.createDataCache(options);
+
+                    ODataReadOracle.readJsonAcrossServerPages(params.feedUri, function (collection) {
+                        assertObservables(params.operator(cache.toObservable()), params.operator(window.Rx.Observable.FromArray(collection.value)), function () {
+                            djstest.destroyCacheAndDone(cache);
+                        });
+                    });
+                }, "feed: " + params.feedUri + ", pageSize: " + params.pageSize + ", operator: " + params.operator.toString(), params);
+            });
+        });
+    });
+})(this);

http://git-wip-us.apache.org/repos/asf/olingo-odata4-js/blob/48761e07/JSLib/tests/odata-fuzz.html
----------------------------------------------------------------------
diff --git a/JSLib/tests/odata-fuzz.html b/JSLib/tests/odata-fuzz.html
new file mode 100644
index 0000000..5d9c35d
--- /dev/null
+++ b/JSLib/tests/odata-fuzz.html
@@ -0,0 +1,561 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+    <title>OData Fuzzing Tests</title>
+    <meta http-equiv="cache-control" content="no-cache" />
+    <meta http-equiv="pragma" content="no-cache" />
+    <meta http-equiv="expires" content="-1" />
+    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
+    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.js"></script>
+
+    <script type="text/javascript" src="../src/datajs.js"></script>
+    <script type="text/javascript" src="../src/utils.js"></script>
+    <script type="text/javascript" src="../src/xml.js"></script>
+
+    <script type="text/javascript" src="../src/odata-utils.js"></script>
+    <script type="text/javascript" src="../src/odata-handler.js"></script>
+    <script type="text/javascript" src="../src/odata-gml.js"></script>
+    <script type="text/javascript" src="../src/odata-xml.js"></script>
+    <script type="text/javascript" src="../src/odata-net.js"></script>
+    <script type="text/javascript" src="../src/odata-json-light.js"></script>
+    <script type="text/javascript" src="../src/odata-json.js"></script>
+    <script type="text/javascript" src="../src/odata-atom.js"></script>
+    <script type="text/javascript" src="../src/odata-metadata.js"></script>
+    <script type="text/javascript" src="../src/odata-batch.js"></script>
+    <script type="text/javascript" src="../src/odata.js"></script>
+
+    <script type="text/javascript" src="../src/store-dom.js"></script>
+    <script type="text/javascript" src="../src/store-indexeddb.js"></script>
+    <script type="text/javascript" src="../src/store-memory.js"></script>
+    <script type="text/javascript" src="../src/store.js"></script>
+  
+    <script type="text/javascript" src="../src/deferred.js"></script>
+    <script type="text/javascript" src="../src/cache-source.js"></script>
+    <script type="text/javascript" src="../src/cache.js"></script>
+
+    <script type="text/javascript">
+
+        var testCsdl = '' +
+        '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\r\n' +
+        '<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">\r\n' +
+        '  <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0">\r\n' +
+        '    <Schema Namespace="TestCatalog.Model" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">\r\n' +
+        '      <EntityType Name="Genre">\r\n' +
+        '        <Key><PropertyRef Name="Name" /></Key>\r\n' +
+        '        <Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="50" Unicode="false" FixedLength="false" m:FC_TargetPath="SyndicationTitle" />\r\n' +
+        '        <NavigationProperty Name="Titles" Relationship="TestCatalog.Model.TitleGenres" FromRole="Genres" ToRole="Titles" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <EntityType Name="Language">\r\n' +
+        '        <Key><PropertyRef Name="Name" /></Key>\r\n' +
+        '        <Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="80" Unicode="false" FixedLength="false" m:FC_TargetPath="SyndicationTitle" />\r\n' +
+        '        <NavigationProperty Name="Titles" Relationship="TestCatalog.Model.TitleLanguages" FromRole="Language" ToRole="Titles" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <EntityType Name="Person">\r\n' +
+        '        <Key><PropertyRef Name="Id" /></Key>\r\n' +
+        '        <Property Name="Id" Type="Edm.Int32" Nullable="false" />\r\n' +
+        '        <Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="80" Unicode="true" FixedLength="false" m:FC_TargetPath="SyndicationTitle" />\r\n' +
+        '        <NavigationProperty Name="Awards" Relationship="TestCatalog.Model.FK_TitleAward_Person" FromRole="People" ToRole="TitleAwards" />\r\n' +
+        '        <NavigationProperty Name="TitlesActedIn" Relationship="TestCatalog.Model.TitleActors" FromRole="People" ToRole="Titles" />\r\n' +
+        '        <NavigationProperty Name="TitlesDirected" Relationship="TestCatalog.Model.TitleDirectors" FromRole="People" ToRole="Titles" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <EntityType Name="TitleAudioFormat">\r\n' +
+        '        <Key><PropertyRef Name="TitleId" /><PropertyRef Name="DeliveryFormat" /><PropertyRef Name="Language" /><PropertyRef Name="Format" /></Key>\r\n' +
+        '        <Property Name="TitleId" Type="Edm.String" Nullable="false" MaxLength="30" FixedLength="false" />\r\n' +
+        '        <Property Name="DeliveryFormat" Type="Edm.String" Nullable="false" MaxLength="10" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Language" Type="Edm.String" Nullable="false" MaxLength="30" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Format" Type="Edm.String" Nullable="false" MaxLength="30" Unicode="false" FixedLength="false" />\r\n' +
+        '        <NavigationProperty Name="Title" Relationship="TestCatalog.Model.FK_TitleAudioFormat_Title" FromRole="TitleAudioFormats" ToRole="Titles" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <EntityType Name="TitleAward">\r\n' +
+        '        <Key><PropertyRef Name="Id" /></Key>\r\n' +
+        '        <Property Name="Id" Type="Edm.Guid" Nullable="false" />\r\n' +
+        '        <Property Name="Type" Type="Edm.String" Nullable="false" MaxLength="30" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Category" Type="Edm.String" Nullable="false" MaxLength="60" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Year" Type="Edm.Int32" Nullable="true" />\r\n' +
+        '        <Property Name="Won" Type="Edm.Boolean" Nullable="false" />\r\n' +
+        '        <NavigationProperty Name="Title" Relationship="TestCatalog.Model.FK_TitleAward_Title" FromRole="TitleAwards" ToRole="Titles" />\r\n' +
+        '        <NavigationProperty Name="Person" Relationship="TestCatalog.Model.FK_TitleAward_Person" FromRole="TitleAwards" ToRole="People" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <EntityType Name="Title" m:HasStream="true">\r\n' +
+        '        <Key><PropertyRef Name="Id" /></Key>\r\n' +
+        '        <Property Name="Id" Type="Edm.String" Nullable="false" MaxLength="30" FixedLength="false" />\r\n' +
+        '        <Property Name="Synopsis" Type="Edm.String" Nullable="true" MaxLength="Max" Unicode="false" FixedLength="false" m:FC_TargetPath="SyndicationSummary" m:FC_ContentKind="html" />\r\n' +
+        '        <Property Name="ShortSynopsis" Type="Edm.String" Nullable="true" MaxLength="Max" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="AverageRating" Type="Edm.Double" Nullable="true" />\r\n' +
+        '        <Property Name="ReleaseYear" Type="Edm.Int32" Nullable="true" />\r\n' +
+        '        <Property Name="Url" Type="Edm.String" Nullable="true" MaxLength="200" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Runtime" Type="Edm.Int32" Nullable="true" />\r\n' +
+        '        <Property Name="Rating" Type="Edm.String" Nullable="true" MaxLength="10" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="DateModified" Type="Edm.DateTime" Nullable="false" ConcurrencyMode="Fixed" m:FC_TargetPath="SyndicationUpdated" m:FC_KeepInContent="false" />\r\n' +
+        '        <Property Name="Type" Type="Edm.String" Nullable="false" MaxLength="8" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="BoxArt" Type="TestCatalog.Model.BoxArt" Nullable="false" />\r\n' +
+        '        <Property Name="ShortName" Type="Edm.String" Nullable="false" MaxLength="200" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Name" Type="Edm.String" Nullable="false" MaxLength="200" Unicode="false" FixedLength="false" m:FC_TargetPath="SyndicationTitle" />\r\n' +
+        '        <Property Name="Instant" Type="TestCatalog.Model.InstantAvailability" Nullable="false" />\r\n' +
+        '        <Property Name="Dvd" Type="TestCatalog.Model.DeliveryFormatAvailability" Nullable="false" />\r\n' +
+        '        <Property Name="BluRay" Type="TestCatalog.Model.DeliveryFormatAvailability" Nullable="false" />\r\n' +
+        '        <Property Name="TinyUrl" Type="Edm.String" Nullable="false" MaxLength="30" />\r\n' +
+        '        <Property Name="WebsiteUrl" Type="Edm.String" Nullable="true" MaxLength="200" />\r\n' +
+        '        <Property Name="TestApiId" Type="Edm.String" Nullable="false" MaxLength="200" />\r\n' +
+        '        <NavigationProperty Name="AudioFormats" Relationship="TestCatalog.Model.FK_TitleAudioFormat_Title" FromRole="Titles" ToRole="TitleAudioFormats" />\r\n' +
+        '        <NavigationProperty Name="Awards" Relationship="TestCatalog.Model.FK_TitleAward_Title" FromRole="Titles" ToRole="TitleAwards" />\r\n' +
+        '        <NavigationProperty Name="Disc" Relationship="TestCatalog.Model.FK_Title_Disc" FromRole="Titles1" ToRole="Titles" />\r\n' +
+        '        <NavigationProperty Name="Movie" Relationship="TestCatalog.Model.FK_Title_Movie" FromRole="Titles1" ToRole="Titles" />\r\n' +
+        '        <NavigationProperty Name="Season" Relationship="TestCatalog.Model.FK_Title_Season" FromRole="Titles1" ToRole="Titles" />\r\n' +
+        '        <NavigationProperty Name="Series" Relationship="TestCatalog.Model.FK_Title_Series" FromRole="Titles1" ToRole="Titles" />\r\n' +
+        '        <NavigationProperty Name="ScreenFormats" Relationship="TestCatalog.Model.FK_TitleScreenFormat_Title" FromRole="Titles" ToRole="TitleScreenFormats" />\r\n' +
+        '        <NavigationProperty Name="Cast" Relationship="TestCatalog.Model.TitleActors" FromRole="Titles" ToRole="People" />\r\n' +
+        '        <NavigationProperty Name="Languages" Relationship="TestCatalog.Model.TitleLanguages" FromRole="Titles" ToRole="Language" />\r\n' +
+        '        <NavigationProperty Name="Directors" Relationship="TestCatalog.Model.TitleDirectors" FromRole="Titles" ToRole="People" />\r\n' +
+        '        <NavigationProperty Name="Genres" Relationship="TestCatalog.Model.TitleGenres" FromRole="Titles" ToRole="Genres" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <ComplexType Name="BoxArt">\r\n' +
+        '        <Property Name="SmallUrl" Type="Edm.String" Nullable="true" MaxLength="80" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="MediumUrl" Type="Edm.String" Nullable="true" MaxLength="80" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="LargeUrl" Type="Edm.String" Nullable="true" MaxLength="80" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="HighDefinitionUrl" Type="Edm.String" Nullable="true" MaxLength="80" Unicode="false" FixedLength="false" />\r\n' +
+        '      </ComplexType>\r\n' +
+        '      <ComplexType Name="InstantAvailability">\r\n' +
+        '        <Property Name="Available" Type="Edm.Boolean" Nullable="false" />\r\n' +
+        '        <Property Name="AvailableFrom" Type="Edm.DateTime" Nullable="true" />\r\n' +
+        '        <Property Name="AvailableTo" Type="Edm.DateTime" Nullable="true" />\r\n' +
+        '        <Property Name="HighDefinitionAvailable" Type="Edm.Boolean" Nullable="false" />\r\n' +
+        '        <Property Name="Runtime" Type="Edm.Int32" Nullable="true" />\r\n' +
+        '        <Property Name="Rating" Type="Edm.String" Nullable="true" MaxLength="10" Unicode="false" FixedLength="false" />\r\n' +
+        '      </ComplexType>\r\n' +
+        '      <ComplexType Name="DeliveryFormatAvailability">\r\n' +
+        '        <Property Name="Available" Type="Edm.Boolean" Nullable="false" />\r\n' +
+        '        <Property Name="AvailableFrom" Type="Edm.DateTime" Nullable="true" />\r\n' +
+        '        <Property Name="AvailableTo" Type="Edm.DateTime" Nullable="true" />\r\n' +
+        '        <Property Name="Runtime" Type="Edm.Int32" Nullable="true" />\r\n' +
+        '        <Property Name="Rating" Type="Edm.String" Nullable="true" MaxLength="10" Unicode="false" FixedLength="false" />\r\n' +
+        '      </ComplexType>\r\n' +
+        '      <EntityType Name="TitleScreenFormat">\r\n' +
+        '        <Key><PropertyRef Name="TitleId" /><PropertyRef Name="DeliveryFormat" /><PropertyRef Name="Format" /></Key>\r\n' +
+        '        <Property Name="TitleId" Type="Edm.String" Nullable="false" MaxLength="30" FixedLength="false" />\r\n' +
+        '        <Property Name="DeliveryFormat" Type="Edm.String" Nullable="false" MaxLength="10" Unicode="false" FixedLength="false" />\r\n' +
+        '        <Property Name="Format" Type="Edm.String" Nullable="false" MaxLength="30" Unicode="false" FixedLength="false" />\r\n' +
+        '        <NavigationProperty Name="Title" Relationship="TestCatalog.Model.FK_TitleScreenFormat_Title" FromRole="TitleScreenFormats" ToRole="Titles" />\r\n' +
+        '      </EntityType>\r\n' +
+        '      <Association Name="FK_TitleAudioFormat_Title">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="1" />\r\n' +
+        '        <End Role="TitleAudioFormats" Type="TestCatalog.Model.TitleAudioFormat" Multiplicity="*" />\r\n' +
+        '        <ReferentialConstraint>\r\n' +
+        '          <Principal Role="Titles"><PropertyRef Name="Id" /></Principal>\r\n' +
+        '          <Dependent Role="TitleAudioFormats"><PropertyRef Name="TitleId" /></Dependent>\r\n' +
+        '        </ReferentialConstraint>\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_TitleAward_Title">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="1" />\r\n' +
+        '        <End Role="TitleAwards" Type="TestCatalog.Model.TitleAward" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_TitleAward_Person">\r\n' +
+        '        <End Role="People" Type="TestCatalog.Model.Person" Multiplicity="0..1" />\r\n' +
+        '        <End Role="TitleAwards" Type="TestCatalog.Model.TitleAward" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_Title_Disc">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="0..1" />\r\n' +
+        '        <End Role="Titles1" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_Title_Movie">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="0..1" />\r\n' +
+        '        <End Role="Titles1" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_Title_Season">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="0..1" />\r\n' +
+        '        <End Role="Titles1" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_Title_Series">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="0..1" />\r\n' +
+        '        <End Role="Titles1" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="FK_TitleScreenFormat_Title">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="1" />\r\n' +
+        '        <End Role="TitleScreenFormats" Type="TestCatalog.Model.TitleScreenFormat" Multiplicity="*" />\r\n' +
+        '        <ReferentialConstraint>\r\n' +
+        '          <Principal Role="Titles"><PropertyRef Name="Id" /></Principal>\r\n' +
+        '          <Dependent Role="TitleScreenFormats"><PropertyRef Name="TitleId" /></Dependent>\r\n' +
+        '        </ReferentialConstraint>\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="TitleActors">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '        <End Role="People" Type="TestCatalog.Model.Person" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="TitleLanguages">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '        <End Role="Language" Type="TestCatalog.Model.Language" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="TitleDirectors">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '        <End Role="People" Type="TestCatalog.Model.Person" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '      <Association Name="TitleGenres">\r\n' +
+        '        <End Role="Titles" Type="TestCatalog.Model.Title" Multiplicity="*" />\r\n' +
+        '        <End Role="Genres" Type="TestCatalog.Model.Genre" Multiplicity="*" />\r\n' +
+        '      </Association>\r\n' +
+        '    </Schema>\r\n' +
+        '    <Schema Namespace="Test.Catalog" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2008/09/edm">\r\n' +
+        '      <EntityContainer Name="TestCatalog" m:IsDefaultEntityContainer="true">\r\n' +
+        '        <FunctionImport Name="Movies" EntitySet="Titles" ReturnType="Collection(TestCatalog.Model.Title)" m:HttpMethod="GET" />\r\n' +
+        '        <FunctionImport Name="Series" EntitySet="Titles" ReturnType="Collection(TestCatalog.Model.Title)" m:HttpMethod="GET" />\r\n' +
+        '        <FunctionImport Name="Seasons" EntitySet="Titles" ReturnType="Collection(TestCatalog.Model.Title)" m:HttpMethod="GET" />\r\n' +
+        '        <FunctionImport Name="Discs" EntitySet="Titles" ReturnType="Collection(TestCatalog.Model.Title)" m:HttpMethod="GET" />\r\n' +
+        '        <FunctionImport Name="Episodes" EntitySet="Titles" ReturnType="Collection(TestCatalog.Model.Title)" m:HttpMethod="GET" />\r\n' +
+        '        <EntitySet Name="Genres" EntityType="TestCatalog.Model.Genre" />\r\n' +
+        '        <EntitySet Name="Languages" EntityType="TestCatalog.Model.Language" />\r\n' +
+        '        <EntitySet Name="People" EntityType="TestCatalog.Model.Person" />\r\n' +
+        '        <EntitySet Name="TitleAudioFormats" EntityType="TestCatalog.Model.TitleAudioFormat" />\r\n' +
+        '        <EntitySet Name="TitleAwards" EntityType="TestCatalog.Model.TitleAward" />\r\n' +
+        '        <EntitySet Name="Titles" EntityType="TestCatalog.Model.Title" />\r\n' +
+        '        <EntitySet Name="TitleScreenFormats" EntityType="TestCatalog.Model.TitleScreenFormat" />\r\n' +
+        '        <AssociationSet Name="FK_TitleAudioFormat_Title" Association="TestCatalog.Model.FK_TitleAudioFormat_Title">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="TitleAudioFormats" EntitySet="TitleAudioFormats" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_TitleAward_Title" Association="TestCatalog.Model.FK_TitleAward_Title">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="TitleAwards" EntitySet="TitleAwards" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_TitleAward_Person" Association="TestCatalog.Model.FK_TitleAward_Person">\r\n' +
+        '          <End Role="People" EntitySet="People" />\r\n' +
+        '          <End Role="TitleAwards" EntitySet="TitleAwards" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_Title_Disc" Association="TestCatalog.Model.FK_Title_Disc">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="Titles1" EntitySet="Titles" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_Title_Movie" Association="TestCatalog.Model.FK_Title_Movie">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="Titles1" EntitySet="Titles" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_Title_Season" Association="TestCatalog.Model.FK_Title_Season">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="Titles1" EntitySet="Titles" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_Title_Series" Association="TestCatalog.Model.FK_Title_Series">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="Titles1" EntitySet="Titles" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="FK_TitleScreenFormat_Title" Association="TestCatalog.Model.FK_TitleScreenFormat_Title">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="TitleScreenFormats" EntitySet="TitleScreenFormats" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="TitleActors" Association="TestCatalog.Model.TitleActors">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="People" EntitySet="People" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="TitleLanguages" Association="TestCatalog.Model.TitleLanguages">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="Language" EntitySet="Languages" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="TitleDirectors" Association="TestCatalog.Model.TitleDirectors">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="People" EntitySet="People" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '        <AssociationSet Name="TitleGenres" Association="TestCatalog.Model.TitleGenres">\r\n' +
+        '          <End Role="Titles" EntitySet="Titles" />\r\n' +
+        '          <End Role="Genres" EntitySet="Genres" />\r\n' +
+        '        </AssociationSet>\r\n' +
+        '      </EntityContainer>\r\n' +
+        '    </Schema>\r\n' +
+        '  </edmx:DataServices>\r\n' +
+        '</edmx:Edmx>\r\n' +
+        '';
+
+
+        var iterationsRemaining = 0;
+        var iterationsPerRun = 100000;
+        var failureCount = 0;
+        var canary = false;
+
+        function canaryFn() {
+            canary = true;
+        }
+
+        var buildSumAndNormalize = function (table) {
+            // Sum all weights.
+            var total = 0;
+            for (var i = 0; i < table.length; i++) {
+                total += table[i].w;
+            }
+
+            // Record a normalized weight (nw) and the step-ladder threshold.
+            var last = 0;
+            for (var i = 0; i < table.length; i++) {
+                table[i].nw = (table[i].w / total);
+
+                last += table[i].nw;
+                table[i].sl = last;
+            }
+
+            table.total = total;
+        };
+
+        var randomFromWeighted = function (table) {
+            if (table.total === undefined) {
+                buildSumAndNormalize(table);
+            }
+
+            var number = Math.random();
+            for (var i = 0; i < table.length; i++) {
+                if (number < table[i].sl) {
+                    return table[i].v;
+                }
+            }
+
+            return table[table.length - 1].v;
+        };
+
+        // Create a table with relative weight w and value v for text generation.
+        var fuzzingTextTable = [
+            { w: 3, v: "canary=true" },
+            { w: 2, v: "canary=true;" },
+            { w: 3, v: "canary=1" },
+            { w: 1, v: "window.canary=1" },
+            { w: 2, v: "canary=[]" },
+            { w: 2, v: "canary={}" },
+            { w: 1, v: "canaryFn" },
+            { w: 2, v: "canaryFn()" }
+        ];
+
+        var fuzzingTextOpTable = [
+            { w: 1, v: "replace" },
+            { w: 3, v: "insert" }
+        ];
+
+        var fuzzText = function (text) {
+            /// <summary>Fuzzes the specified string.</summary>
+            /// <param name="text" type="String">Text to fuzz.</param>
+            /// <returns type="String">The fuzzes text.</returns>
+
+            var location = Math.round(Math.random() * text.length - 1);
+            var content = randomFromWeighted(fuzzingTextTable);
+            var op = randomFromWeighted(fuzzingTextOpTable);
+            if (op === "replace") {
+                text = text.substr(0, location) + content + text.substr(location + content.length);
+            } else if (op === "insert") {
+                text = text.substr(0, location) + content + text.substr(location);
+            }
+
+            return text;
+        };
+
+        var rarely = function (rare, common) {
+            if (Math.random() < 0.1) {
+                return rare;
+            } else {
+                return common;
+            }
+        };
+
+        var gibberish = function () {
+            var len = Math.random() * 100;
+            var result = "";
+            for (var i = 0; i < len; i++) {
+                result += String.fromCharCode(Math.round(Math.random() * 65000));
+            }
+
+            return result;
+        }
+
+        var generateResponse = function (suggestedContentType, body) {
+            var url = rarely(null, "http://foo/bar");
+            var statusCode = rarely((Math.random() * 1000).toString().substr(0, 3), 200);
+            var statusText = rarely(gibberish(), "OK");
+            var headers = [];
+            headers["Content-Length"] = rarely(Math.random() * 200, undefined);
+            headers["Content-Type"] = rarely("foo bar baz", suggestedContentType);
+
+            var response = { requestUri: url, statusCode: statusCode, statusText: statusText, headers: headers, body: body };
+            return response;
+        };
+
+        var generateRandom = function () {
+            var body = gibberish();
+            return generateResponse("application/octet-stream", body);
+        };
+
+        var generateServiceDoc = function() {
+            var body = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>\r\n' +
+                        '<service xml:base="http://services.odata.org/OData/OData.svc/"  xmlns:atom="http://www.w3.org/2005/Atom" ' +
+                        ' xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">' +
+                        '<workspace><atom:title>Default</atom:title> <collection href="Products"><atom:title>Products</atom:title></collection>' +
+                        '<collection href="Categories"><atom:title>Categories</atom:title> </collection><collection href="Suppliers"><atom:title>Suppliers</atom:title> </collection></workspace></service>';
+            body = fuzzText(body);
+            return generateResponse("application/atomsvc+xml", body);
+        };
+
+        var generateMetadata = function () {
+            var body = testCsdl;
+            body = fuzzText(body);
+            return generateResponse("application/xml", body);
+        };
+
+        var generateError = function () {
+            var body = testCsdl;
+            body = fuzzText(body);
+            return generateResponse("application/xml", body);
+        };
+
+        var generatePlainText = function () {
+            var body = gibberish();
+            return generateResponse("plain/text", body);
+        };
+
+        var generateBatch = function () {
+            var body = gibberish();
+            return generateResponse("multipart/mixed; boundary=batch(123)", body);
+        };
+
+        var generateXml = function () {
+            // TODO: consider doing something about an XHTML section here
+            var body = '' +
+                '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\r\n' +
+                '<feed xml:base=http://services.odata.org/OData/OData.svc/' +
+                '     xmlns:d=http://schemas.microsoft.com/ado/2007/08/dataservices' +
+                '     xmlns:m=http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' +
+                '     xmlns="http://www.w3.org/2005/Atom">' +
+                '  <title type="text">Categories</title>' +
+                '  <id>http://services.odata.org/OData/OData.svc/Categories</id>' +
+                '  <updated>2010-03-10T08:38:14Z</updated>' +
+                '  <link rel="self" title="Categories" href="Categories" />' +
+                '  <entry>' +
+                '    <id>http://services.odata.org/OData/OData.svc/Categories(0)</id>' +
+                '    <title type="text">Food</title>' +
+                '    <updated>2010-03-10T08:38:14Z</updated>' +
+                '    <author><name /></author>' +
+                '    <link rel="edit" title="Category" href="Categories(0)" />' +
+                '    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products"' +
+                '            type="application/atom+xml;type=feed"' +
+                '            title="Products" href="Categories(0)/Products" />' +
+                '    <category term="ODataDemo.Category"' +
+                '            scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />' +
+                '    <content type="application/xml">' +
+                '      <m:properties>' +
+                '        <d:ID m:type="Edm.Int32">0</d:ID>' +
+                '        <d:Name>Food</d:Name>' +
+                '        <d:AverageRating m:type="Edm.Double">3.6</d:AverageRating>' +
+                '        <d:AvailableFrom m:type="Edm.DateTime">1999-03-23T00:00:00</d:AvailableFrom>' +
+                '        <d:Name>Food</d:Name>' +
+                '      </m:properties>' +
+                '    </content>' +
+                '  </entry>' +
+                '  <!-- <entry> elements representing additional Categories go here -->' +
+                '</feed>';
+            return generateResponse("application/atom+xml", body);
+        };
+
+        var generateJson = function () {
+            var body =  '{ "d" : { ' +
+                        '"results": [ ' +
+                        '{ ' +
+                        '"__metadata": {  ' +
+                        '"uri": "http://services.odata.org/OData/OData.svc/Categories(0)",  ' +
+                        '"type": "DataServiceProviderDemo.Category" ' +
+                        '}, ' +
+                        '"ID": 0, ' +
+                        '"Name": "Food", ' +
+                        '"SomeDate": "Date(123)", ' +
+                        '"Products": { ' +
+                        '"__deferred": { ' +
+                        '"uri": "http://services.odata.org/OData/OData.svc/Categories(0)/Products" ' +
+                        '} } } ], ' +
+                        '"__count": "3", ' +
+                        '"__next": "http://services.odata.org/OData/OData.svc$skiptoken=12" ' +
+                        '} } ' +
+                        '';
+            return generateResponse("application/json", body);
+        };
+
+        // Create a table with relative weight w and value v for response generation.
+        var formatTable = [
+            { w:  1, v: generateRandom },
+            { w:  2, v: generateError },
+            { w:  5, v: generatePlainText },
+            { w:  5, v: generateServiceDoc },
+            { w: 10, v: generateBatch },
+            { w: 10, v: generateMetadata },
+            { w: 40, v: generateXml },
+            { w: 80, v: generateJson }
+        ];
+
+        var fakeHttpClient = {
+            request: function (request, success, error) {
+                /// <summary>Performs a network request.</summary>
+                /// <param name="success" type="Function">Success callback with the response object.</param>
+                /// <param name="error" type="Function">Error callback with an error object.</param>
+                /// <returns type="Object">Object with an 'abort' method for the operation.</returns>
+
+                var shouldError = rarely(true, false);
+                var format = randomFromWeighted(formatTable);
+                var response = format();
+
+                window.setTimeout(function () {
+                    if (shouldError) {
+                        error(response);
+                    } else {
+                        success(response);
+                    }
+                }, 1);
+
+                return {};
+            }
+        };
+
+        var startTimeMs = 0;
+
+        function startTest() {
+            failureCount = 0;
+            startTimeMs = new Date().getTime();
+            iterationsRemaining = iterationsPerRun;
+            nextIteration();
+        }
+
+        function readCallback() {
+            // Success or failure don't actually matter.
+            if (canary === true) {
+                canary = false;
+                failureCount++;
+            }
+
+            iterationsRemaining--;
+            nextIteration();
+        }
+
+        function nextIteration() {
+            if (iterationsRemaining === 0) {
+                $("#fuzz-status").text("Tests complete. Failures: #" + failureCount);
+                return;
+            }
+
+            if (iterationsRemaining % 50 === 0) {
+                var text = "Running tests (pending=" + iterationsRemaining + " of " + iterationsPerRun;
+                if (iterationsRemaining !== iterationsPerRun) {
+                    var currentTimeMs = new Date().getTime();
+                    var averageTestTimeMs = (iterationsPerRun - iterationsRemaining) / (currentTimeMs - startTimeMs);
+                    var remainingTimeMs = iterationsRemaining * averageTestTimeMs;
+                    text += ", ETA: " + remainingTimeMs + "ms, avg " + averageTestTimeMs + "ms";
+                }
+
+                text += "). Failures: #" + failureCount;
+                $("#fuzz-status").text(text);
+            }
+
+            OData.read("url", readCallback, readCallback, undefined, fakeHttpClient);
+        }
+
+        $(document).ready(function () {
+            $("#start-button").click(startTest);
+        });
+    </script>
+
+</head>
+<body>
+<h1>OData Fuzzing Tests</h1>
+<p>
+This page fuzzes the OData parsers in the datajs library.
+</p>
+<button id='start-button'>Start</button>
+<p id='fuzz-status'>&nbsp;</p>
+</body>
+</html>