-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_subscriber.js
182 lines (173 loc) · 5.92 KB
/
test_subscriber.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"use strict";
var DOMAIN_ID = 32;
var ddsCerts = process.env.DDS_ROOT + "/tests/security/certs/identity";
function str2arr(input) {
return input.split('');
}
var qos = { user_data: { value: str2arr('foo') } };
var secure = process.argv.includes('--secure');
if (secure) {
qos.property = {
value: [
{
name: "dds.sec.auth.identity_ca",
value: "file:" + ddsCerts + "/identity_ca_cert.pem"
},
{
name: "dds.sec.access.permissions_ca",
value: "file:" + ddsCerts + "/identity_ca_cert.pem"
},
{
name: "dds.sec.access.governance",
value: "file:" + "security/governance_signed.p7s"
},
{
name: "dds.sec.auth.identity_certificate",
value: "file:" + ddsCerts + "/test_participant_02_cert.pem"
},
{
name: "dds.sec.auth.private_key",
value: "file:" + ddsCerts + "/test_participant_02_private_key.pem"
},
{
name: "dds.sec.access.permissions",
value: "file:" + "security/sub_permissions_signed.p7s"
}
]
};
}
function init_opendds(opendds_addon) {
return opendds_addon.initialize(... process.argv.slice(2));
}
var opendds_addon = require('../lib/node-opendds'),
factory = init_opendds(opendds_addon),
library = opendds_addon.load('idl/NodeJSTest'),
participant = factory.create_participant(DOMAIN_ID, qos),
reader,
last_sample_id = 24,
dds_inf = 0x7fffffff,
infinite = { sec: dds_inf, nanosec: dds_inf };
function log(label, object) {
console.log(label + ': ' + JSON.stringify(object, (key, value) => typeof value === 'bigint' ? value.toString() : value, 2));
}
function doStuff(participant, reader) {
console.log("reader has waited long enough for acknowledgments");
participant.unsubscribe(reader);
}
try {
if (!library) {
throw 'Failed to load shared library';
}
reader = participant.subscribe('topic', 'Mod::Sample', {
ContentFilteredTopic: {
filter_expression: 'id < %0',
expression_parameters: ['30']
},
SubscriberQos: {
presentation: {
access_scope: 'INSTANCE_PRESENTATION_QOS',
coherent_access: false,
ordered_access: false
},
group_data: { value: str2arr('test') }
},
DataReaderQos: {
durability: { kind: 'VOLATILE_DURABILITY_QOS' },
latency_budget: { duration: { sec: 1, nanosec: 0 } },
liveliness: {
kind: 'AUTOMATIC_LIVELINESS_QOS',
lease_duration: infinite
},
reliability: {
kind: 'RELIABLE_RELIABILITY_QOS',
max_blocking_time: { sec: 1, nanosec: 0 }
},
destination_order: { kind: 'BY_RECEPTION_TIMESTAMP_DESTINATIONORDER_QOS' },
history: {
kind: 'KEEP_LAST_HISTORY_QOS',
depth: 10
},
resource_limits: {
max_samples: 1000,
max_instances: 100,
max_samples_per_instance: 10
},
user_data: { value: str2arr('arbitrary string') },
ownership: { kind: 'SHARED_OWNERSHIP_QOS' },
time_based_filter: { minimum_separation: { sec: 0, nanosec: 0 } },
reader_data_lifecycle: {
autopurge_nowriter_samples_delay: infinite,
autopurge_disposed_samples_delay: infinite
}
}
}, function (dr, sinfo, sample) {
try {
log('Sample Info', sinfo);
if (sinfo.valid_data) {
log('Received callback', sample);
if (!(sample.id == 23 || sample.id == 24) ||
sample.data != "Hello, world\n" ||
sample.enu != "two" ||
sample.enu2 != "three" ||
sample.bt.o != 254 ||
sample.bt.us != 65500 ||
sample.bt.s != 32700 ||
sample.bt.ul != 3000000000 ||
sample.bt.l != 100000 ||
sample.bt.ull != "12379813738877118345" ||
sample.bt.ll != 5000000000 ||
sample.bt.f > (2.17 + 1e-3) || sample.bt.f < (2.17 - 1e-3) || // avoid direct floating point comparisons by testing epsilon ranges
sample.bt.d > (3.14 + 1e-6) || sample.bt.d < (3.14 - 1e-6) ||
sample.bt.ld > (1.4142136 + 1e-9) || sample.bt.ld < (1.4142136 - 1e-9) ||
sample.bt.b != true ||
sample.bt.c != "x" ||
sample.bt.str != "z012" ||
sample.bt.wstr != "abcde" ||
sample.seq1.length != 5 ||
sample.seq1[0] != 0 ||
sample.seq1[1] != 45 ||
sample.seq1[2] != 90 ||
sample.seq1[3] != 135 ||
sample.seq1[4] != 180 ||
sample.seq2.length != 3 ||
sample.seq2[0] != 32 ||
sample.seq2[1] != 33 ||
sample.seq2[2] != 34 ||
sample.ns.length != 2 ||
sample.ns[0].length != 4 ||
sample.ns[0][0] != "string1" ||
sample.ns[0][1] != "string2" ||
sample.ns[0][2] != "string3" ||
sample.ns[0][3] != "string4" ||
sample.ns[1].length != 1 ||
sample.ns[1][0] != "string5" ||
sample.ca[0] != "n" ||
sample.ca[1] != "i" ||
sample.ca[2] != "n" ||
sample.ca[3] != "j" ||
sample.ca[4] != "a" ||
sample.ca[5] != "s" ||
sample.sa[0] != "north" ||
sample.sa[1] != "east" ||
sample.sa[2] != "south" ||
sample.sa[3] != "west" ||
(sample.id == 23 && (sample.mu.$discriminator != "one" || sample.mu.a != 6)) ||
(sample.id == 24 && (sample.mu.$discriminator != "four" || sample.mu.s.length != 2 || sample.mu.s[0].length != 4 || sample.mu.s[1].length != 1))) {
console.log("Error in data!");
process.exitCode = 1;
}
if (sample.id == last_sample_id) {
setTimeout(function () { doStuff(participant, dr); }, 10000);
}
}
} catch (e) {
console.log("Error in callback: " + e);
}
});
} catch (e) {
console.log(e);
}
process.on('exit', function () {
factory.delete_participant(participant); // optional
opendds_addon.finalize(factory);
});