flok 0.0.65 → 0.0.66

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58af4b75f2c646d66f7249cab77f1a550b393f00
4
- data.tar.gz: 88ec49b2a0e62a185956debdf4b39e3be76c8f6f
3
+ metadata.gz: a14b04d730ef3b9aacd8c74e5e4d4aaefe985fa0
4
+ data.tar.gz: 9b938591a91b898de270c24a5cbea1b7f83ffd3a
5
5
  SHA512:
6
- metadata.gz: db62e8d340aeae8645db9210d6bbefaef8120c45580dd973967951509abad2c2701c5ef3c662e434866f341355d6f9ace279fd72b064050c385960b00ea87de1
7
- data.tar.gz: 631469402017511a3d0fc1df7985b577ac965973f94718635f6e021cab426a7650b4c22951f9cfb2036e17ce4c562454fa656549449c4873ff9b957f24e7fee0
6
+ metadata.gz: aeaa0959cfa1e56fff2003ce9e0925c6c5384886a0f82da48269bc9e71b14b3684199b5c72e75bfb5793d2edf33860dd3484749307070b4287574ae413dafee9
7
+ data.tar.gz: 229329809c8dc148b1a01223d8e3a340ada05bb4d169736aba82578c06614f6f1446c3900a2bf9101ea65410642357698ac89f7f71ac732cd6cfbeaff5881428
@@ -0,0 +1,50 @@
1
+ //Configure pg_sockio
2
+ <% [0].each do |i| %>
3
+ function pg_sockio<%= i %>_init(ns, options) {
4
+ pg_sockio<%= i %>_ns = ns;
5
+
6
+ if (options.url === undefined) {
7
+ throw "pg_sockio<%= i %> was not given a url in options";
8
+ }
9
+
10
+ <% if @debug %>
11
+ pg_sockio<%= i %>_spec_did_init = true;
12
+ <% end %>
13
+
14
+ //Destination for events sent from the sockio driver
15
+ function pg_sockio<%= i %>_xevent_handler(ep, ename, einfo) {
16
+ if (ename === "update") {
17
+ vm_transaction_begin();
18
+ vm_cache_write(pg_sockio<%= i %>_ns, einfo.page);
19
+ vm_transaction_end();
20
+ } else {
21
+ <% if @debug %>
22
+ throw "pg_sockio<%= i %>_xevent_handler received an event called: " + ename + "that it does not know how to handle. This event should never have even been forwarded, but you may have missed adding the handler code if you did request a forward"
23
+ <% end %>
24
+ }
25
+ }
26
+
27
+ //Register the base address for the socket and the destination for events
28
+ pg_sockio<%= i %>_bp = tels(1);
29
+ reg_evt(pg_sockio<%= i %>_bp, pg_sockio<%= i %>_xevent_handler);
30
+
31
+ SEND("net", "if_sockio_init", options.url, pg_sockio<%= i %>_bp);
32
+
33
+ //Signal that the socket.io driver should forward all events to the socket defined by pg_sockio{N}_bp
34
+ //to the endpoint (with the same reference)
35
+ SEND("net", "if_sockio_fwd", pg_sockio<%= i %>_bp, "update", pg_sockio<%= i %>_bp);
36
+ }
37
+
38
+ function pg_sockio<%= i %>_watch(id, page) {
39
+ var info = {
40
+ page_id: id
41
+ };
42
+ SEND("net", "if_sockio_send", pg_sockio<%= i %>_bp, "watch", info);
43
+ }
44
+
45
+ function pg_sockio<%= i %>_unwatch(id) {
46
+ }
47
+
48
+ function pg_sockio<%= i %>_write(page) {
49
+ }
50
+ <% end %>
@@ -57,3 +57,29 @@ This pager provides you with local memory that will be automatically cached to d
57
57
 
58
58
  ####Dummy pager | `pg_dummy0`
59
59
  This pager doesn't do anything. Used by some specs which manually write to the vm_cache in leu of the pager
60
+
61
+ ####Sockio pager | `pg_sockio0`
62
+ This pager connects to a socket.io server via the `sockio` module.
63
+ * **Options**
64
+ * `url (required)` - The url of the socket.io server you are connecting to. Includes endpoint if that's required for your socket.io server. E.g.
65
+ `http://myapp.com/socket`
66
+ * **Globals**
67
+ * `pg_sockio{N}_bp` - The base address that the socket exists at (`sp`) and the endpoint that events are sent to that are destined for forwarding.
68
+ * `pg_sockio{N}_xevent_handler` - Events received by the sockio driver are forwarded to the kernel at a certain event endpoint if they are
69
+ configured via `if_sockio_fwd`. This `xevent_handler` is the destination for all forwarding requests for the `pg_sockio#{N}` socket. Note
70
+ that the endpoint shares the same value as the socket's base pointer.
71
+ * **Functions**
72
+ * `init` - Will begin trying to establish a connection to the server. When pages are written,
73
+ * `watch` - Signals to the socket.io server that a page is being watched via `watch` event with parameters `{page_id:}`
74
+ * `unwatch` - Signals to the socket.io server that a page is no longer being watched via `unwatch` event with parameters `{page_id:}`
75
+ * `write` -
76
+ * If the page already exists:
77
+ * Commits unsynced changes to `vm_cache` and notifies the server of the changes if the page already existed via `/update` with `page_id:,
78
+ changes:`
79
+ * If the page does not exist:
80
+ * writes directly to `vm_cache` and notifies the server of the creation via `/create` with `page:`
81
+ * **Socket.IO Event Handlers **
82
+ * `update` - A page has been updated. This may either indicate an update or write. The page will be integrated into `vm_cache` via a rebased if it
83
+ already exists or a direct write if it dosen't already exist. Contains one field `page:` that contains the page.
84
+ * **Spec**
85
+ * If `@debug`, then `sockio{N}_spec_did_init` will be true
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.65"
2
+ VERSION = "0.0.66"
3
3
  end
@@ -0,0 +1,12 @@
1
+ #Simple service config that uses built-in spec service to create a instance called 'spec'
2
+ service_instance :vm, :vm, {
3
+ :pagers => [
4
+ {
5
+ :name => "pg_sockio0",
6
+ :namespace => "sockio",
7
+ :options => {
8
+ :url => "http://localhost"
9
+ }
10
+ }
11
+ ]
12
+ }
@@ -0,0 +1,11 @@
1
+ #Simple service config that uses built-in spec service to create a instance called 'spec'
2
+ service_instance :vm, :vm, {
3
+ :pagers => [
4
+ {
5
+ :name => "pg_sockio0",
6
+ :namespace => "sockio",
7
+ :options => {
8
+ }
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,12 @@
1
+ controller :my_controller do
2
+ services :vm
3
+
4
+ action :my_action do
5
+ on_entry %{
6
+ }
7
+
8
+ on "read_res", %{
9
+ read_res_params = params;
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ controller :my_controller do
2
+ services :vm
3
+
4
+ action :my_action do
5
+ on_entry %{
6
+ var watch_info = {
7
+ ns: "sockio",
8
+ id: "test",
9
+ };
10
+
11
+ Request("vm", "watch", watch_info);
12
+ }
13
+
14
+ on "read_res", %{
15
+ read_res_params = params;
16
+ }
17
+ end
18
+ end
@@ -0,0 +1,117 @@
1
+ #The pg_sockio pager
2
+
3
+ Dir.chdir File.join File.dirname(__FILE__), '../../'
4
+ require './spec/env/kern.rb'
5
+ require './spec/lib/helpers.rb'
6
+ require './spec/lib/io_extensions.rb'
7
+ require './spec/lib/rspec_extensions.rb'
8
+ require 'zlib'
9
+
10
+ RSpec.describe "kern:sockio_pager" do
11
+ include Zlib
12
+ include_context "kern"
13
+
14
+ it "Can initialize the pg_sockio0 pager" do
15
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/pg_sockio/nothing.rb'), File.read("./spec/kern/assets/vm/pg_sockio/config.rb")
16
+ ctx.eval %{
17
+ //Call embed on main root view
18
+ base = _embed("my_controller", 0, {}, null);
19
+
20
+ //Drain queue
21
+ int_dispatch([]);
22
+ }
23
+
24
+ res = ctx.eval("pg_sockio0_spec_did_init")
25
+ expect(res).to eq(true)
26
+ end
27
+
28
+ it "Does throw an exception if not given a url" do
29
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/pg_sockio/nothing.rb'), File.read("./spec/kern/assets/vm/pg_sockio/config_no_url.rb")
30
+
31
+ expect {
32
+ ctx.eval %{
33
+ //Call embed on main root view
34
+ base = _embed("my_controller", 0, {}, null);
35
+
36
+ //Drain queue
37
+ int_dispatch([]);
38
+ }
39
+ }.to raise_error(/url/)
40
+ end
41
+
42
+ it "Does initialize a socketio connection" do
43
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/pg_sockio/nothing.rb'), File.read("./spec/kern/assets/vm/pg_sockio/config.rb")
44
+ ctx.evald %{
45
+ //Call embed on main root view
46
+ dump.base = _embed("my_controller", 0, {}, null);
47
+
48
+ //Drain queue
49
+ int_dispatch([]);
50
+
51
+ dump.pg_sockio0_bp = pg_sockio0_bp;
52
+ }
53
+
54
+ #URL is specified in the config
55
+ @driver.ignore_up_to "if_sockio_init", 1
56
+ @driver.mexpect "if_sockio_init", ["http://localhost", Integer], 1
57
+
58
+ #Forward the update event
59
+ @driver.ignore_up_to "if_sockio_fwd", 1
60
+ @driver.mexpect "if_sockio_fwd", [Integer, "update", dump["pg_sockio0_bp"]], 1
61
+ end
62
+
63
+ it "Does send a watch request via socket.io when a page is watched" do
64
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/pg_sockio/watch.rb'), File.read("./spec/kern/assets/vm/pg_sockio/config.rb")
65
+ ctx.eval %{
66
+ //Call embed on main root view
67
+ base = _embed("my_controller", 0, {}, null);
68
+
69
+ //Drain queue
70
+ int_dispatch([]);
71
+ }
72
+
73
+ #We are sending a watch request for a page named 'test'
74
+ @driver.ignore_up_to "if_sockio_send", 1
75
+ @driver.mexpect "if_sockio_send", [Integer, "watch", {
76
+ "page_id" => "test"
77
+ }], 1
78
+ end
79
+
80
+ it "Does write a page to vm_cache that dosen't already exist when the page receives an 'update' response from the external socket.io" do
81
+ ctx = flok_new_user File.read('./spec/kern/assets/vm/pg_sockio/watch.rb'), File.read("./spec/kern/assets/vm/pg_sockio/config.rb")
82
+ dump = ctx.evald %{
83
+ //Call embed on main root view
84
+ dump.base = _embed("my_controller", 0, {}, null);
85
+
86
+ //Drain queue
87
+ int_dispatch([]);
88
+
89
+ //pg_sockio0 socket address & the endpoint for the event callback
90
+ dump.pg_sockio0_bp = pg_sockio0_bp;
91
+ }
92
+
93
+ #We received a watch request for a page with the id 'test'
94
+ #Now we are imagining that the socket.io driver received back some
95
+ #data and is now signaling to the kernel that data is available
96
+ @driver.int "int_event", [dump["pg_sockio0_bp"], "update", {page: {
97
+ _id: "test",
98
+ _next: nil,
99
+ _head: nil,
100
+ entries: [
101
+ {"_id" => "foo", "_sig" => "foo", "value" => "bar"}
102
+ ],
103
+ }}]
104
+
105
+ post_read_res_dump = ctx.evald %{
106
+ //Drain queue (vm_cache_write defers to controller)
107
+ int_dispatch([]);
108
+
109
+ dump.read_res_params = read_res_params;
110
+ }
111
+
112
+ #The controller should have received a notification that a page was updated
113
+ expect(post_read_res_dump["read_res_params"]["entries"]).to eq([
114
+ {"_id" => "foo", "_sig" => "foo", "value" => "bar"}
115
+ ])
116
+ end
117
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flok
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.65
4
+ version: 0.0.66
5
5
  platform: ruby
6
6
  authors:
7
7
  - seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-17 00:00:00.000000000 Z
11
+ date: 2015-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -297,6 +297,7 @@ files:
297
297
  - app/kern/pagers/pg_dummy.js
298
298
  - app/kern/pagers/pg_mem.js
299
299
  - app/kern/pagers/pg_net_sim.js
300
+ - app/kern/pagers/pg_sockio.js
300
301
  - app/kern/pagers/pg_spec.js
301
302
  - app/kern/pagers/sockio_pager.js
302
303
  - app/kern/pagers/spec0.js
@@ -1253,6 +1254,10 @@ files:
1253
1254
  - spec/kern/assets/vm/pg_net_sim/nothing.rb
1254
1255
  - spec/kern/assets/vm/pg_net_sim/pages.json
1255
1256
  - spec/kern/assets/vm/pg_net_sim/watch.rb
1257
+ - spec/kern/assets/vm/pg_sockio/config.rb
1258
+ - spec/kern/assets/vm/pg_sockio/config_no_url.rb
1259
+ - spec/kern/assets/vm/pg_sockio/nothing.rb
1260
+ - spec/kern/assets/vm/pg_sockio/watch.rb
1256
1261
  - spec/kern/assets/vm/service0.rb
1257
1262
  - spec/kern/assets/vm/service_controller0.rb
1258
1263
  - spec/kern/assets/vm/vm_commit_pages.js
@@ -1273,6 +1278,7 @@ files:
1273
1278
  - spec/kern/vm_service_mem_pagers_spec.rb
1274
1279
  - spec/kern/vm_service_net_sim_pager_spec.rb
1275
1280
  - spec/kern/vm_service_spec.rb
1281
+ - spec/kern/vm_sockio_pager_spec.rb
1276
1282
  - spec/kern/vm_transaction_spec.rb
1277
1283
  - spec/lib/helpers.rb
1278
1284
  - spec/lib/io_extensions.rb
@@ -2182,6 +2188,10 @@ test_files:
2182
2188
  - spec/kern/assets/vm/pg_net_sim/nothing.rb
2183
2189
  - spec/kern/assets/vm/pg_net_sim/pages.json
2184
2190
  - spec/kern/assets/vm/pg_net_sim/watch.rb
2191
+ - spec/kern/assets/vm/pg_sockio/config.rb
2192
+ - spec/kern/assets/vm/pg_sockio/config_no_url.rb
2193
+ - spec/kern/assets/vm/pg_sockio/nothing.rb
2194
+ - spec/kern/assets/vm/pg_sockio/watch.rb
2185
2195
  - spec/kern/assets/vm/service0.rb
2186
2196
  - spec/kern/assets/vm/service_controller0.rb
2187
2197
  - spec/kern/assets/vm/vm_commit_pages.js
@@ -2202,6 +2212,7 @@ test_files:
2202
2212
  - spec/kern/vm_service_mem_pagers_spec.rb
2203
2213
  - spec/kern/vm_service_net_sim_pager_spec.rb
2204
2214
  - spec/kern/vm_service_spec.rb
2215
+ - spec/kern/vm_sockio_pager_spec.rb
2205
2216
  - spec/kern/vm_transaction_spec.rb
2206
2217
  - spec/lib/helpers.rb
2207
2218
  - spec/lib/io_extensions.rb