@optimystic/quereus-plugin-optimystic 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +358 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +2973 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-B1lVAVv0.d.ts +596 -0
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.js +2873 -0
- package/dist/plugin.js.map +1 -0
- package/examples/README.md +232 -0
- package/examples/quoomb.config.absolute.json +22 -0
- package/examples/quoomb.config.dev.json +16 -0
- package/examples/quoomb.config.linked.json +25 -0
- package/examples/quoomb.config.local.json +22 -0
- package/examples/quoomb.config.node1.json +23 -0
- package/examples/quoomb.config.node2.env.json +28 -0
- package/examples/quoomb.config.node2.json +29 -0
- package/examples/quoomb.config.single-node.json +25 -0
- package/examples/quoomb.config.web.json +30 -0
- package/examples/start-mesh.ps1 +48 -0
- package/examples/start-mesh.sh +44 -0
- package/examples/test-comprehensive.sql +25 -0
- package/examples/test-manual-plugin.txt +23 -0
- package/examples/test-multi-insert.sql +11 -0
- package/examples/test-network.sql +20 -0
- package/examples/test-plugin.sql +20 -0
- package/examples/test-single-insert.sql +20 -0
- package/examples/test-single-node.sql +20 -0
- package/package.json +131 -0
- package/src/functions/transaction-id.ts +29 -0
- package/src/index.ts +42 -0
- package/src/optimystic-adapter/collection-factory.ts +337 -0
- package/src/optimystic-adapter/key-network.ts +106 -0
- package/src/optimystic-adapter/txn-bridge.ts +272 -0
- package/src/optimystic-adapter/vtab-connection.ts +76 -0
- package/src/optimystic-module.ts +1064 -0
- package/src/plugin.ts +64 -0
- package/src/schema/index-manager.ts +266 -0
- package/src/schema/row-codec.ts +312 -0
- package/src/schema/schema-manager.ts +217 -0
- package/src/schema/statistics-collector.ts +173 -0
- package/src/transaction/index.ts +16 -0
- package/src/transaction/quereus-engine.ts +174 -0
- package/src/types.ts +91 -0
- package/src/util/generate-transaction-id.ts +41 -0
- package/test/README.md +313 -0
package/test/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# Testing Guide
|
|
2
|
+
|
|
3
|
+
This guide explains how to test the Optimystic Quereus plugin.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Run all tests
|
|
9
|
+
yarn workspace @optimystic/quereus-plugin-optimystic test
|
|
10
|
+
|
|
11
|
+
# Run only distributed tests
|
|
12
|
+
yarn workspace @optimystic/quereus-plugin-optimystic exec aegir test -t node -- --grep "Distributed"
|
|
13
|
+
|
|
14
|
+
# Run manual mesh test
|
|
15
|
+
yarn workspace @optimystic/quereus-plugin-optimystic build
|
|
16
|
+
node packages/quereus-plugin-optimystic/dist/test/manual-mesh-test.js
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Test Suites
|
|
20
|
+
|
|
21
|
+
### Unit Tests
|
|
22
|
+
|
|
23
|
+
- **`transaction-id.spec.ts`** - TransactionId() function tests (11 tests)
|
|
24
|
+
- **`schema-support.spec.ts`** - Schema and table creation tests
|
|
25
|
+
- **`index-support.spec.ts`** - Index support tests
|
|
26
|
+
|
|
27
|
+
### Distributed Tests
|
|
28
|
+
|
|
29
|
+
- **`distributed-quereus.spec.ts`** - Automated distributed operations tests (4 tests)
|
|
30
|
+
- **`distributed-transaction-validation.spec.ts`** - Transaction validation tests with file storage (5 tests)
|
|
31
|
+
- **`manual-mesh-test.ts`** - Interactive manual testing script
|
|
32
|
+
|
|
33
|
+
### Transaction Validation Tests (Phase 7)
|
|
34
|
+
|
|
35
|
+
The `distributed-transaction-validation.spec.ts` suite tests end-to-end distributed transactions with:
|
|
36
|
+
|
|
37
|
+
- **Real file storage** (`FileRawStorage`) instead of memory
|
|
38
|
+
- **CHECK constraint validation** independently on each peer
|
|
39
|
+
- **StampId-based non-repeatability** via `WITH CONTEXT`
|
|
40
|
+
- **Multi-collection transactions** (table + index coordination)
|
|
41
|
+
- **Concurrent transactions** with constraint enforcement
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Run transaction validation tests
|
|
45
|
+
yarn workspace @optimystic/quereus-plugin-optimystic exec aegir test -t node -- --grep "Transaction Validation"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Distributed Testing
|
|
49
|
+
|
|
50
|
+
The distributed tests create a mesh of N nodes, perform DML operations (INSERT, UPDATE, DELETE), and verify data replication across all nodes.
|
|
51
|
+
|
|
52
|
+
## Automated Test Suite
|
|
53
|
+
|
|
54
|
+
### Running the Tests
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Build the plugin first
|
|
58
|
+
yarn workspace @optimystic/quereus-plugin-optimystic build
|
|
59
|
+
|
|
60
|
+
# Run the distributed tests
|
|
61
|
+
yarn workspace @optimystic/quereus-plugin-optimystic exec aegir test -t node -- --grep "Distributed Quereus"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### What It Tests
|
|
65
|
+
|
|
66
|
+
The automated suite includes 4 test cases:
|
|
67
|
+
|
|
68
|
+
1. **Table Creation** - Creates a table on one node, verifies it's accessible from another
|
|
69
|
+
2. **INSERT Distribution** - Inserts data from different nodes, verifies all nodes see all data
|
|
70
|
+
3. **UPDATE Replication** - Updates data on one node, verifies the update propagates to all nodes
|
|
71
|
+
4. **DELETE Replication** - Deletes data on one node, verifies the deletion propagates to all nodes
|
|
72
|
+
|
|
73
|
+
### Configuration
|
|
74
|
+
|
|
75
|
+
Edit `distributed-quereus.spec.ts` to change:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const MESH_SIZE = 3; // Number of nodes in the mesh
|
|
79
|
+
const BASE_PORT = 9100; // Starting port number
|
|
80
|
+
const NETWORK_NAME = 'test-distributed-quereus'; // Network identifier
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Manual Interactive Test
|
|
84
|
+
|
|
85
|
+
### Running the Manual Test
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Build first
|
|
89
|
+
yarn workspace @optimystic/quereus-plugin-optimystic build
|
|
90
|
+
|
|
91
|
+
# Run with default settings (3 nodes)
|
|
92
|
+
node packages/quereus-plugin-optimystic/dist/test/manual-mesh-test.js
|
|
93
|
+
|
|
94
|
+
# Run with custom mesh size
|
|
95
|
+
MESH_SIZE=5 node packages/quereus-plugin-optimystic/dist/test/manual-mesh-test.js
|
|
96
|
+
|
|
97
|
+
# Run with custom port and network name
|
|
98
|
+
MESH_SIZE=4 BASE_PORT=9300 NETWORK_NAME=my-test node packages/quereus-plugin-optimystic/dist/test/manual-mesh-test.js
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Environment Variables
|
|
102
|
+
|
|
103
|
+
- `MESH_SIZE` - Number of nodes to create (default: 3)
|
|
104
|
+
- `BASE_PORT` - Starting port number (default: 9200)
|
|
105
|
+
- `NETWORK_NAME` - Network identifier (default: 'manual-test-mesh')
|
|
106
|
+
|
|
107
|
+
### What It Does
|
|
108
|
+
|
|
109
|
+
The manual test runs a complete scenario:
|
|
110
|
+
|
|
111
|
+
1. **Creates mesh** - Starts N nodes and connects them
|
|
112
|
+
2. **Creates tables** - Creates the same table on all nodes
|
|
113
|
+
3. **Inserts data** - Inserts different rows from different nodes
|
|
114
|
+
4. **Verifies replication** - Checks all nodes see all data
|
|
115
|
+
5. **Updates data** - Updates a row from one node
|
|
116
|
+
6. **Verifies update** - Checks all nodes see the update
|
|
117
|
+
7. **Deletes data** - Deletes a row from another node
|
|
118
|
+
8. **Verifies deletion** - Checks all nodes see the deletion
|
|
119
|
+
9. **Tests TransactionId()** - Verifies the TransactionId() function works on all nodes
|
|
120
|
+
|
|
121
|
+
### Example Output
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
🚀 Starting 3-node Quereus mesh
|
|
125
|
+
|
|
126
|
+
Network: manual-test-mesh
|
|
127
|
+
Base Port: 9200
|
|
128
|
+
|
|
129
|
+
🔧 Creating node on port 9200...
|
|
130
|
+
✅ Node created: 12D3KooWAbc...
|
|
131
|
+
🔧 Creating node on port 9201...
|
|
132
|
+
✅ Node created: 12D3KooWDef...
|
|
133
|
+
🔧 Creating node on port 9202...
|
|
134
|
+
✅ Node created: 12D3KooWGhi...
|
|
135
|
+
|
|
136
|
+
⏳ Waiting for network convergence...
|
|
137
|
+
|
|
138
|
+
📊 Network Status:
|
|
139
|
+
Node 1 (12D3KooWAbc...): 2 connections
|
|
140
|
+
Node 2 (12D3KooWDef...): 2 connections
|
|
141
|
+
Node 3 (12D3KooWGhi...): 2 connections
|
|
142
|
+
|
|
143
|
+
✅ Mesh ready!
|
|
144
|
+
|
|
145
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
146
|
+
📝 Test Scenario: Distributed DML Operations
|
|
147
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
148
|
+
|
|
149
|
+
Step 1: Creating table on all nodes...
|
|
150
|
+
✓ Node 1: Table created
|
|
151
|
+
✓ Node 2: Table created
|
|
152
|
+
✓ Node 3: Table created
|
|
153
|
+
|
|
154
|
+
Step 2: Inserting data from different nodes...
|
|
155
|
+
✓ Node 1: Inserted Alice
|
|
156
|
+
✓ Node 2: Inserted Bob
|
|
157
|
+
✓ Node 3: Inserted Charlie
|
|
158
|
+
|
|
159
|
+
Step 3: Verifying data replication...
|
|
160
|
+
✓ Node 1: 3 rows
|
|
161
|
+
Alice, Bob, Charlie
|
|
162
|
+
✓ Node 2: 3 rows
|
|
163
|
+
Alice, Bob, Charlie
|
|
164
|
+
✓ Node 3: 3 rows
|
|
165
|
+
Alice, Bob, Charlie
|
|
166
|
+
|
|
167
|
+
Step 4: Updating data from Node 1...
|
|
168
|
+
✓ Updated Alice's email
|
|
169
|
+
|
|
170
|
+
Step 5: Verifying update replication...
|
|
171
|
+
✓ Node 1: alice.updated@example.com
|
|
172
|
+
✓ Node 2: alice.updated@example.com
|
|
173
|
+
✓ Node 3: alice.updated@example.com
|
|
174
|
+
|
|
175
|
+
Step 6: Deleting data from Node 2...
|
|
176
|
+
✓ Deleted Bob
|
|
177
|
+
|
|
178
|
+
Step 7: Verifying deletion replication...
|
|
179
|
+
✓ Node 1: 2 rows remaining
|
|
180
|
+
Alice, Charlie
|
|
181
|
+
✓ Node 2: 2 rows remaining
|
|
182
|
+
Alice, Charlie
|
|
183
|
+
✓ Node 3: 2 rows remaining
|
|
184
|
+
Alice, Charlie
|
|
185
|
+
|
|
186
|
+
Step 8: Testing TransactionId() function...
|
|
187
|
+
✓ Node 1: abc123def456...
|
|
188
|
+
✓ Node 2: ghi789jkl012...
|
|
189
|
+
✓ Node 3: mno345pqr678...
|
|
190
|
+
|
|
191
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
192
|
+
✅ All operations completed successfully!
|
|
193
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
194
|
+
|
|
195
|
+
🛑 Stopping all nodes...
|
|
196
|
+
✅ All nodes stopped
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## How It Works
|
|
200
|
+
|
|
201
|
+
### Node Creation
|
|
202
|
+
|
|
203
|
+
Each node is created with:
|
|
204
|
+
|
|
205
|
+
1. **libp2p node** - P2P networking layer
|
|
206
|
+
2. **Storage** - In-memory storage (MemoryRawStorage)
|
|
207
|
+
3. **NetworkTransactor** - Optimystic transaction coordinator
|
|
208
|
+
4. **Quereus Database** - SQL database engine
|
|
209
|
+
5. **Optimystic Plugin** - Registered with the database
|
|
210
|
+
|
|
211
|
+
### Network Topology
|
|
212
|
+
|
|
213
|
+
- **Bootstrap Node** (Node 1) - Started first, provides addresses for other nodes
|
|
214
|
+
- **Peer Nodes** (Nodes 2-N) - Connect to bootstrap node and discover each other
|
|
215
|
+
- **Mesh Network** - All nodes eventually connect to each other
|
|
216
|
+
|
|
217
|
+
### Data Replication
|
|
218
|
+
|
|
219
|
+
When a DML operation is performed:
|
|
220
|
+
|
|
221
|
+
1. **Local Write** - Data is written to the local Optimystic tree
|
|
222
|
+
2. **Network Sync** - Changes are synced to the distributed network via libp2p
|
|
223
|
+
3. **Cluster Coordination** - FRET (Flexible Routing and Efficient Topology) ensures data reaches all nodes
|
|
224
|
+
4. **Eventual Consistency** - All nodes eventually see the same data
|
|
225
|
+
|
|
226
|
+
### Timing Considerations
|
|
227
|
+
|
|
228
|
+
The tests include delays to allow for:
|
|
229
|
+
|
|
230
|
+
- **Network convergence** (3000ms) - Nodes discovering each other
|
|
231
|
+
- **Data propagation** (500-1500ms) - Changes replicating across the network
|
|
232
|
+
|
|
233
|
+
These delays may need adjustment based on:
|
|
234
|
+
- Network latency
|
|
235
|
+
- Number of nodes
|
|
236
|
+
- System performance
|
|
237
|
+
|
|
238
|
+
## Troubleshooting
|
|
239
|
+
|
|
240
|
+
### Nodes Not Connecting
|
|
241
|
+
|
|
242
|
+
If nodes aren't connecting:
|
|
243
|
+
|
|
244
|
+
1. Check firewall settings
|
|
245
|
+
2. Verify ports are available
|
|
246
|
+
3. Increase convergence delay
|
|
247
|
+
4. Check bootstrap addresses are correct
|
|
248
|
+
|
|
249
|
+
### Data Not Replicating
|
|
250
|
+
|
|
251
|
+
If data isn't replicating:
|
|
252
|
+
|
|
253
|
+
1. Increase propagation delays
|
|
254
|
+
2. Check network connections (connection count)
|
|
255
|
+
3. Verify all nodes use the same `collectionUri`
|
|
256
|
+
4. Check for errors in node logs
|
|
257
|
+
|
|
258
|
+
### Tests Timing Out
|
|
259
|
+
|
|
260
|
+
If tests timeout:
|
|
261
|
+
|
|
262
|
+
1. Increase mocha timeout in `.aegir.js`
|
|
263
|
+
2. Reduce `MESH_SIZE`
|
|
264
|
+
3. Increase delays between operations
|
|
265
|
+
|
|
266
|
+
## Advanced Usage
|
|
267
|
+
|
|
268
|
+
### Testing with More Nodes
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
const MESH_SIZE = 10; // Test with 10 nodes
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Note: More nodes require:
|
|
275
|
+
- More time for convergence
|
|
276
|
+
- More memory
|
|
277
|
+
- Longer propagation delays
|
|
278
|
+
|
|
279
|
+
### Testing Different Operations
|
|
280
|
+
|
|
281
|
+
Add custom test scenarios:
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
it('should handle concurrent transactions', async () => {
|
|
285
|
+
// Your test code here
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Using Different Storage
|
|
290
|
+
|
|
291
|
+
Replace `MemoryRawStorage` with `FileRawStorage`:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { FileRawStorage } from '@optimystic/db-p2p';
|
|
295
|
+
|
|
296
|
+
const rawStorage = new FileRawStorage('./test-data/node-' + port);
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Related Files
|
|
300
|
+
|
|
301
|
+
- `packages/reference-peer/test/distributed-diary.spec.ts` - Similar tests for Diary (lower-level)
|
|
302
|
+
- `packages/quereus-plugin-optimystic/examples/` - Example configs for manual testing
|
|
303
|
+
- `TEST-SETUP-SUMMARY.md` - Overview of test infrastructure
|
|
304
|
+
|
|
305
|
+
## Next Steps
|
|
306
|
+
|
|
307
|
+
After running these tests, you can:
|
|
308
|
+
|
|
309
|
+
1. **Add more test cases** - Test complex queries, transactions, constraints
|
|
310
|
+
2. **Test failure scenarios** - Network partitions, node failures
|
|
311
|
+
3. **Performance testing** - Measure replication latency, throughput
|
|
312
|
+
4. **Integration testing** - Test with real applications
|
|
313
|
+
|