This is the distribution library. When loaded, distribution introduces functionality supporting the distributed execution of programs. To download it:
$ npm i '@brown-ds/distribution'This command downloads and installs the distribution library.
There are several categories of tests:
- Regular Tests (
*.test.js) - Scenario Tests (
*.scenario.js) - Extra Credit Tests (
*.extra.test.js) - Student Tests (
*.student.test.js) - insidetest/test-student
By default, all regular tests are run. Use the options below to run different sets of tests:
- Run all regular tests (default):
$ npm testor$ npm test -- -t - Run scenario tests:
$ npm test -- -c - Run extra credit tests:
$ npm test -- -ec - Run the
non-distributiontests:$ npm test -- -nd - Combine options:
$ npm test -- -c -ec -nd -t
To import the library, be it in a JavaScript file or on the interactive console, run:
let distribution = require("@brown-ds/distribution");Now you have access to the full distribution library. You can start off by serializing some values.
let s = distribution.util.serialize(1); // '{"type":"number","value":"1"}'
let n = distribution.util.deserialize(s); // 1You can inspect information about the current node (for example its sid) by running:
distribution.local.status.get('sid', console.log); // 8cf1bYou can also store and retrieve values from the local memory:
distribution.local.mem.put({name: 'nikos'}, 'key', console.log); // {name: 'nikos'}
distribution.local.mem.get('key', console.log); // {name: 'nikos'}You can also spawn a new node:
let node = { ip: '127.0.0.1', port: 8080 };
distribution.local.status.spawn(node, console.log);Using the distribution.all set of services will allow you to act
on the full set of nodes created as if they were a single one.
distribution.all.status.get('sid', console.log); // { '8cf1b': '8cf1b', '8cf1c': '8cf1c' }You can also send messages to other nodes:
distribution.all.comm.send(['sid'], {node: node, service: 'status', method: 'get'}, console.log); // 8cf1c...