Compare commits
2 Commits
1b86a9252d
...
7205cc1ea3
| Author | SHA1 | Date | |
|---|---|---|---|
| 7205cc1ea3 | |||
| aa7cdbd36f |
32
README.md
32
README.md
@@ -47,9 +47,9 @@ NATSBridge enables seamless communication across multiple platforms through NATS
|
||||
| Platform | Implementation | Features |
|
||||
|----------|----------------|----------|
|
||||
| **Julia** | [`src/NATSBridge.jl`](src/NATSBridge.jl) | Full feature set, Arrow IPC, multiple dispatch |
|
||||
| **JavaScript** | [`src/natbridge.js`](src/natbridge.js) | Node.js & browser, async/await |
|
||||
| **Python** | [`src/natbridge.py`](src/natbridge.py) | Desktop Python, asyncio, type hints |
|
||||
| **MicroPython** | [`src/natbridge_mpy.py`](src/natbridge_mpy.py) | Memory-constrained, synchronous API |
|
||||
| **JavaScript** | [`src/natsbridge.js`](src/natsbridge.js) | Node.js & browser, async/await |
|
||||
| **Python** | [`src/natsbridge.py`](src/natsbridge.py) | Desktop Python, asyncio, type hints |
|
||||
| **MicroPython** | [`src/natsbridge_mpy.py`](src/natsbridge_mpy.py) | Memory-constrained, synchronous API |
|
||||
|
||||
### Platform Comparison
|
||||
|
||||
@@ -332,7 +332,7 @@ env, env_json_str = NATSBridge.smartsend(
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
subject,
|
||||
@@ -361,7 +361,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
env, env_json_str = await NATSBridge.smartsend(
|
||||
subject: str,
|
||||
@@ -388,7 +388,7 @@ env, env_json_str = await NATSBridge.smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
# Limited to direct transport (< 100KB threshold)
|
||||
env, env_json_str = NATSBridge.smartsend(
|
||||
@@ -551,7 +551,7 @@ env, env_json_str = NATSBridge.smartsend("/chat/room1", data; fileserver_url="ht
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
const data = [
|
||||
["message_text", "Hello!", "text"],
|
||||
@@ -569,7 +569,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
data = [
|
||||
("message_text", "Hello!", "text"),
|
||||
@@ -606,7 +606,7 @@ env, env_json_str = NATSBridge.smartsend("/device/config", data)
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
const config = {
|
||||
wifi_ssid: "MyNetwork",
|
||||
@@ -623,7 +623,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
config = {
|
||||
"wifi_ssid": "MyNetwork",
|
||||
@@ -658,7 +658,7 @@ env, env_json_str = NATSBridge.smartsend("/data/analysis", data)
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
const df = [
|
||||
{ id: 1, name: "Alice", score: 95 },
|
||||
@@ -675,7 +675,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
import pandas as pd
|
||||
|
||||
df = pd.DataFrame({
|
||||
@@ -735,7 +735,7 @@ end
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
// Requester
|
||||
const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
@@ -748,7 +748,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
```javascript
|
||||
// Responder
|
||||
const nats = require('nats');
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
async function testResponder() {
|
||||
const conn = await nats.connect('nats://localhost:4222');
|
||||
@@ -782,7 +782,7 @@ async function testResponder() {
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
# Requester
|
||||
env, env_json_str = await NATSBridge.smartsend(
|
||||
@@ -795,7 +795,7 @@ env, env_json_str = await NATSBridge.smartsend(
|
||||
|
||||
```python
|
||||
# Responder
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
import asyncio
|
||||
import nats
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ env = smartreceive(msg; fileserver_download_handler=_fetch_with_backoff)
|
||||
|
||||
**JavaScript:**
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
// Send
|
||||
const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
@@ -104,7 +104,7 @@ const env = await NATSBridge.smartreceive(msg, {
|
||||
|
||||
**Python:**
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
# Send
|
||||
env, env_json_str = NATSBridge.smartsend(
|
||||
@@ -124,7 +124,7 @@ env = NATSBridge.smartreceive(
|
||||
|
||||
**MicroPython:**
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
# Send (limited to direct transport due to memory constraints)
|
||||
env, env_json_str = NATSBridge.smartsend(
|
||||
|
||||
@@ -16,9 +16,9 @@ This document describes the implementation of the high-performance, bi-direction
|
||||
| Language | Implementation File | Description |
|
||||
|----------|---------------------|-------------|
|
||||
| **Julia** | [`src/NATSBridge.jl`](../src/NATSBridge.jl) | Full Julia implementation with Arrow IPC support |
|
||||
| **JavaScript** | `src/natbridge.js` | Node.js/browser implementation |
|
||||
| **Python** | `src/natbridge.py` | Desktop Python implementation |
|
||||
| **MicroPython** | `src/natbridge_mpy.py` | MicroPython implementation (limited features) |
|
||||
| **JavaScript** | `src/natsbridge.js` | Node.js/browser implementation |
|
||||
| **Python** | `src/natsbridge.py` | Desktop Python implementation |
|
||||
| **MicroPython** | `src/natsbridge_mpy.py` | MicroPython implementation (limited features) |
|
||||
|
||||
---
|
||||
|
||||
@@ -228,7 +228,7 @@ end
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('natbridge');
|
||||
const NATSBridge = require('natsbridge');
|
||||
|
||||
// Single payload
|
||||
const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
@@ -275,7 +275,7 @@ for (const [dataname, data, type] of env.payloads) {
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
# Single payload
|
||||
env, env_json_str = await NATSBridge.smartsend(
|
||||
@@ -317,7 +317,7 @@ for dataname, data, type_ in env["payloads"]:
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge import NATSBridge
|
||||
from natsbridge import NATSBridge
|
||||
|
||||
# Limited to text and binary (no tables due to memory constraints)
|
||||
env, env_json_str = NATSBridge.smartsend(
|
||||
@@ -929,7 +929,7 @@ end
|
||||
#### Module Structure
|
||||
|
||||
```javascript
|
||||
// natbridge.js
|
||||
// natsbridge.js
|
||||
const nats = require('nats');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
const fetch = require('node-fetch');
|
||||
@@ -1272,7 +1272,7 @@ async function plikOneshotUpload(file_server_url, dataname, data) {
|
||||
#### Module Structure
|
||||
|
||||
```python
|
||||
# natbridge.py
|
||||
# natsbridge.py
|
||||
import asyncio
|
||||
import base64
|
||||
import json
|
||||
@@ -1690,7 +1690,7 @@ MicroPython has significant constraints compared to desktop implementations:
|
||||
### MicroPython Module Structure
|
||||
|
||||
```python
|
||||
# natbridge_mpy.py (MicroPython)
|
||||
# natsbridge_mpy.py (MicroPython)
|
||||
import network
|
||||
import time
|
||||
import json
|
||||
|
||||
@@ -134,7 +134,7 @@ env, env_json_str = smartsend("/chat/room1", data, broker_url="nats://localhost:
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Send a text message
|
||||
const data = [["message", "Hello World", "text"]];
|
||||
@@ -158,7 +158,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Send a text message
|
||||
data = [("message", "Hello World", "text")]
|
||||
@@ -185,7 +185,7 @@ env, env_json_str = await smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -218,7 +218,7 @@ end
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Receive and process message
|
||||
const env = await NATSBridge.smartreceive(msg, {
|
||||
@@ -233,7 +233,7 @@ for (const [dataname, data, type] of env.payloads) {
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartreceive, fetch_with_backoff
|
||||
from natsbridge import smartreceive, fetch_with_backoff
|
||||
|
||||
# Receive and process message
|
||||
env = await smartreceive(
|
||||
@@ -269,7 +269,7 @@ env, env_json_str = smartsend("/device/config", data, broker_url="nats://localho
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
const config = {
|
||||
wifi_ssid: "MyNetwork",
|
||||
@@ -288,7 +288,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
config = {
|
||||
"wifi_ssid": "MyNetwork",
|
||||
@@ -307,7 +307,7 @@ env, env_json_str = await smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -342,7 +342,7 @@ env, env_json_str = smartsend("/chat/image", data, broker_url="nats://localhost:
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
// Read image file
|
||||
@@ -359,7 +359,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Read image file
|
||||
with open("image.png", "rb") as f:
|
||||
@@ -376,7 +376,7 @@ env, env_json_str = await smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -413,7 +413,7 @@ env, env_json_str = smartsend(
|
||||
#### JavaScript (Requester)
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Send command with reply-to
|
||||
const data = [["command", { action: "read_sensor" }, "dictionary"]];
|
||||
@@ -431,7 +431,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python (Requester)
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Send command with reply-to
|
||||
data = [("command", {"action": "read_sensor"}, "dictionary")]
|
||||
@@ -506,7 +506,7 @@ println("File uploaded to: $(env.payloads[1].data)")
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Create large data (> 1MB)
|
||||
const large_data = Buffer.alloc(2_000_000);
|
||||
@@ -530,7 +530,7 @@ console.log("File uploaded to:", env.payloads[0].data);
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Create large data (> 1MB)
|
||||
import os
|
||||
@@ -552,7 +552,7 @@ print(f"File uploaded to: {env['payloads'][0]['data']}")
|
||||
MicroPython enforces a hard limit of 50KB per payload:
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -590,7 +590,7 @@ env, env_json_str = smartsend("/chat/mixed", data, broker_url="nats://localhost:
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
const image_data = fs.readFileSync('avatar.png');
|
||||
@@ -610,7 +610,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
with open("avatar.png", "rb") as f:
|
||||
image_data = f.read()
|
||||
@@ -652,7 +652,7 @@ env, env_json_str = smartsend("/data/students", data, broker_url="nats://localho
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Create table data (array of objects)
|
||||
const table_data = [
|
||||
@@ -672,7 +672,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
import pandas as pd
|
||||
|
||||
# Create DataFrame
|
||||
|
||||
@@ -177,7 +177,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/chat_ui.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
class ChatUI {
|
||||
constructor() {
|
||||
@@ -333,7 +333,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/chat_handler.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const nats = require('nats');
|
||||
|
||||
class ChatHandler {
|
||||
@@ -393,7 +393,7 @@ module.exports = ChatHandler;
|
||||
# src/chat_handler.py
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
from natbridge import smartreceive, fetch_with_backoff
|
||||
from natsbridge import smartreceive, fetch_with_backoff
|
||||
|
||||
class ChatHandler:
|
||||
def __init__(self, nats_connection):
|
||||
@@ -526,7 +526,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/file_upload_service.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
class FileUploadService {
|
||||
@@ -580,7 +580,7 @@ module.exports = FileUploadService;
|
||||
|
||||
```python
|
||||
# src/file_upload_service.py
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
import os
|
||||
|
||||
class FileUploadService:
|
||||
@@ -659,7 +659,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/file_download_service.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
class FileDownloadService {
|
||||
@@ -690,7 +690,7 @@ module.exports = FileDownloadService;
|
||||
|
||||
```python
|
||||
# src/file_download_service.py
|
||||
from natbridge import smartreceive, fetch_with_backoff
|
||||
from natsbridge import smartreceive, fetch_with_backoff
|
||||
import os
|
||||
|
||||
class FileDownloadService:
|
||||
@@ -832,7 +832,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/sensor_data.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
class SensorReading {
|
||||
constructor(sensorId, value, unit, metadata = {}) {
|
||||
@@ -985,7 +985,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/sensor_sender.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const { SensorReading, SensorBatch } = require('./sensor_data.js');
|
||||
|
||||
class SensorSender {
|
||||
@@ -1069,7 +1069,7 @@ module.exports = SensorSender;
|
||||
|
||||
```python
|
||||
# src/sensor_sender.py
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
from sensor_data import SensorReading, SensorBatch
|
||||
|
||||
class SensorSender:
|
||||
@@ -1282,7 +1282,7 @@ end
|
||||
# Cache file server responses
|
||||
import asyncio
|
||||
import threading
|
||||
from natbridge import fetch_with_backoff
|
||||
from natsbridge import fetch_with_backoff
|
||||
|
||||
file_cache = {}
|
||||
cache_lock = threading.Lock()
|
||||
|
||||
@@ -6,7 +6,7 @@ This module provides functionality for sending and receiving data across network
|
||||
using NATS as the message bus, with support for both direct payload transport and
|
||||
URL-based transport for larger payloads.
|
||||
|
||||
@package natbridge
|
||||
@package natsbridge
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartreceive function with binary/image/audio/video payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
|
||||
@@ -18,15 +19,15 @@ async function runTest() {
|
||||
const genericBinary = Buffer.from([0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE, 0xBA, 0xBE]);
|
||||
|
||||
const testData = {
|
||||
correlation_id: 'js-binary-receiver-' + Date.now(),
|
||||
msg_id: 'msg-' + Date.now(),
|
||||
correlation_id: 'js-binary-receiver-' + crypto.randomUUID(),
|
||||
msg_id: 'msg-' + crypto.randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
send_to: '/test/binary',
|
||||
msg_purpose: 'test',
|
||||
sender_name: 'js-binary-test',
|
||||
sender_id: 'sender-' + Date.now(),
|
||||
sender_id: 'sender-' + crypto.randomUUID(),
|
||||
receiver_name: 'js-receiver',
|
||||
receiver_id: 'receiver-' + Date.now(),
|
||||
receiver_id: 'receiver-' + crypto.randomUUID(),
|
||||
reply_to: '',
|
||||
reply_to_msg_id: '',
|
||||
broker_url: TEST_BROKER_URL,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartsend function with binary/image/audio/video payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_SUBJECT = '/test/binary';
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
|
||||
async function runTest() {
|
||||
console.log('=== JavaScript Binary Sender Test ===\n');
|
||||
|
||||
const correlationId = NATSBridge.uuidv4();
|
||||
const correlationId = crypto.randomUUID();
|
||||
console.log(`Correlation ID: ${correlationId}`);
|
||||
console.log(`Subject: ${TEST_SUBJECT}`);
|
||||
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartreceive function with dictionary payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
|
||||
@@ -18,15 +19,15 @@ async function runTest() {
|
||||
const mixedDict = { string: 'text', number: 123, boolean: true, null_val: null };
|
||||
|
||||
const testData = {
|
||||
correlation_id: 'test-receiver-dict-' + Date.now(),
|
||||
msg_id: 'msg-' + Date.now(),
|
||||
correlation_id: 'test-receiver-dict-' + crypto.randomUUID(),
|
||||
msg_id: 'msg-' + crypto.randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
send_to: '/test/dictionary',
|
||||
msg_purpose: 'test',
|
||||
sender_name: 'js-dict-test',
|
||||
sender_id: 'sender-' + Date.now(),
|
||||
sender_id: 'sender-' + crypto.randomUUID(),
|
||||
receiver_name: 'js-receiver',
|
||||
receiver_id: 'receiver-' + Date.now(),
|
||||
receiver_id: 'receiver-' + crypto.randomUUID(),
|
||||
reply_to: '',
|
||||
reply_to_msg_id: '',
|
||||
broker_url: TEST_BROKER_URL,
|
||||
@@ -161,15 +162,15 @@ async function runTest() {
|
||||
// Test round-trip with receive
|
||||
console.log('\n=== Round-trip Test ===');
|
||||
const roundTripData = {
|
||||
correlation_id: 'roundtrip-' + Date.now(),
|
||||
msg_id: 'msg-' + Date.now(),
|
||||
correlation_id: 'roundtrip-' + crypto.randomUUID(),
|
||||
msg_id: 'msg-' + crypto.randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
send_to: '/test/dictionary',
|
||||
msg_purpose: 'test',
|
||||
sender_name: 'js-test',
|
||||
sender_id: 'sender-' + Date.now(),
|
||||
sender_id: 'sender-' + crypto.randomUUID(),
|
||||
receiver_name: 'js-receiver',
|
||||
receiver_id: 'receiver-' + Date.now(),
|
||||
receiver_id: 'receiver-' + crypto.randomUUID(),
|
||||
reply_to: '',
|
||||
reply_to_msg_id: '',
|
||||
broker_url: TEST_BROKER_URL,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartsend function with dictionary payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_SUBJECT = '/test/dictionary';
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
|
||||
async function runTest() {
|
||||
console.log('=== JavaScript Dictionary Sender Test ===\n');
|
||||
|
||||
const correlationId = NATSBridge.uuidv4();
|
||||
const correlationId = crypto.randomUUID();
|
||||
console.log(`Correlation ID: ${correlationId}`);
|
||||
console.log(`Subject: ${TEST_SUBJECT}`);
|
||||
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
|
||||
|
||||
216
test/test_js_mix_payloads_receiver.js
Normal file
216
test/test_js_mix_payloads_receiver.js
Normal file
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* JavaScript Mix Payloads Receiver Test
|
||||
* Tests the smartreceive function with mixed payload types
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const nats = require('nats');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_SUBJECT = '/test/mix';
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
|
||||
|
||||
async function runTest() {
|
||||
console.log('=== JavaScript Mix Payloads Receiver Test ===\n');
|
||||
|
||||
const correlationId = crypto.randomUUID();
|
||||
console.log(`Correlation ID: ${correlationId}`);
|
||||
console.log(`Subject: ${TEST_SUBJECT}`);
|
||||
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
|
||||
|
||||
// Expected test data - same as sender
|
||||
const expectedTextData = 'Hello, NATSBridge!';
|
||||
const expectedDictData = { key1: 'value1', key2: 42, nested: { a: 1, b: 2 } };
|
||||
const expectedBinaryData = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]); // PNG header
|
||||
const expectedTableData = [
|
||||
{ id: 1, name: 'Alice', age: 30 },
|
||||
{ id: 2, name: 'Bob', age: 25 },
|
||||
{ id: 3, name: 'Charlie', age: 35 }
|
||||
];
|
||||
|
||||
const expectedDatanames = ['message', 'config', 'image', 'users'];
|
||||
const expectedTypes = ['text', 'dictionary', 'image', 'table'];
|
||||
|
||||
let testPassed = true;
|
||||
let messagesReceived = 0;
|
||||
const receivedPayloads = [];
|
||||
|
||||
try {
|
||||
// Connect to NATS
|
||||
console.log('Connecting to NATS server...');
|
||||
const nc = await nats.connect({ servers: TEST_BROKER_URL });
|
||||
console.log('✅ Connected to NATS server\n');
|
||||
|
||||
// Set up message subscription
|
||||
const subscription = nc.subscribe(TEST_SUBJECT);
|
||||
|
||||
// Wait for messages with timeout
|
||||
const messagePromise = new Promise(async (resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
resolve('timeout');
|
||||
}, 10000); // 10 second timeout
|
||||
|
||||
(async () => {
|
||||
for await (const msg of subscription) {
|
||||
clearTimeout(timeout);
|
||||
messagesReceived++;
|
||||
console.log(`\n=== Message ${messagesReceived} Received ===`);
|
||||
console.log(`Raw payload length: ${msg.payload.length} bytes`);
|
||||
|
||||
try {
|
||||
// Process the message using smartreceive
|
||||
const envelope = await NATSBridge.smartreceive(msg, {
|
||||
fileserver_download_handler: NATSBridge.fetchWithBackoff,
|
||||
max_retries: 5,
|
||||
base_delay: 100,
|
||||
max_delay: 5000
|
||||
});
|
||||
|
||||
console.log(`Correlation ID: ${envelope.correlation_id}`);
|
||||
console.log(`Message ID: ${envelope.msg_id}`);
|
||||
console.log(`Number of payloads: ${envelope.payloads.length}`);
|
||||
|
||||
receivedPayloads.push(envelope);
|
||||
|
||||
// Validate envelope structure
|
||||
console.log('\n=== Envelope Validation ===');
|
||||
|
||||
if (envelope.payloads.length < 4) {
|
||||
console.log(`❌ Expected at least 4 payloads, got ${envelope.payloads.length}`);
|
||||
testPassed = false;
|
||||
} else {
|
||||
console.log(`✅ Correct number of payloads: ${envelope.payloads.length}`);
|
||||
}
|
||||
|
||||
// Validate each payload
|
||||
for (let i = 0; i < envelope.payloads.length; i++) {
|
||||
const [dataname, data, dataType] = envelope.payloads[i];
|
||||
|
||||
console.log(`\n--- Payload ${i + 1}: ${dataname} (type: ${dataType}) ---`);
|
||||
|
||||
// Check dataname
|
||||
if (i < expectedDatanames.length && dataname !== expectedDatanames[i]) {
|
||||
console.log(`❌ Expected dataname '${expectedDatanames[i]}', got '${dataname}'`);
|
||||
testPassed = false;
|
||||
} else {
|
||||
console.log(`✅ Correct dataname: ${dataname}`);
|
||||
}
|
||||
|
||||
// Check data type
|
||||
if (i < expectedTypes.length && dataType !== expectedTypes[i]) {
|
||||
console.log(`❌ Expected type '${expectedTypes[i]}', got '${dataType}'`);
|
||||
testPassed = false;
|
||||
} else {
|
||||
console.log(`✅ Correct type: ${dataType}`);
|
||||
}
|
||||
|
||||
// Validate data based on type
|
||||
if (dataType === 'text') {
|
||||
if (typeof data === 'string' && data === expectedTextData) {
|
||||
console.log(`✅ Text data verified: "${data}"`);
|
||||
} else {
|
||||
console.log(`❌ Text data mismatch. Expected: "${expectedTextData}", Got: "${data}"`);
|
||||
testPassed = false;
|
||||
}
|
||||
} else if (dataType === 'dictionary') {
|
||||
if (typeof data === 'object' && JSON.stringify(data) === JSON.stringify(expectedDictData)) {
|
||||
console.log(`✅ Dictionary data verified`);
|
||||
console.log(` Keys: ${Object.keys(data).join(', ')}`);
|
||||
} else {
|
||||
console.log(`❌ Dictionary data mismatch`);
|
||||
console.log(` Expected: ${JSON.stringify(expectedDictData)}`);
|
||||
console.log(` Got: ${JSON.stringify(data)}`);
|
||||
testPassed = false;
|
||||
}
|
||||
} else if (dataType === 'image') {
|
||||
if (data instanceof Buffer || data instanceof Uint8Array) {
|
||||
const dataBuffer = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
||||
if (dataBuffer.length === expectedBinaryData.length) {
|
||||
let dataMatch = true;
|
||||
for (let j = 0; j < expectedBinaryData.length; j++) {
|
||||
if (dataBuffer[j] !== expectedBinaryData[j]) {
|
||||
dataMatch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (dataMatch) {
|
||||
console.log(`✅ Image data verified (${dataBuffer.length} bytes)`);
|
||||
} else {
|
||||
console.log(`❌ Image data mismatch`);
|
||||
testPassed = false;
|
||||
}
|
||||
} else {
|
||||
console.log(`❌ Image data length mismatch. Expected: ${expectedBinaryData.length}, Got: ${dataBuffer.length}`);
|
||||
testPassed = false;
|
||||
}
|
||||
} else {
|
||||
console.log(`❌ Image data is not a Buffer or Uint8Array`);
|
||||
testPassed = false;
|
||||
}
|
||||
} else if (dataType === 'table') {
|
||||
// For table data, check if it's an Arrow table-like object
|
||||
if (data && typeof data === 'object') {
|
||||
// Arrow tables have specific properties
|
||||
if (data.numRows !== undefined && data.numCols !== undefined) {
|
||||
console.log(`✅ Table data verified`);
|
||||
console.log(` Rows: ${data.numRows}, Columns: ${data.numCols}`);
|
||||
} else {
|
||||
console.log(`⚠️ Table data received but not standard Arrow format`);
|
||||
console.log(` Keys: ${Object.keys(data).join(', ')}`);
|
||||
}
|
||||
} else {
|
||||
console.log(`❌ Table data is not a valid object`);
|
||||
testPassed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stop after receiving at least one valid message
|
||||
if (messagesReceived >= 1) {
|
||||
resolve('done');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`❌ Error processing message: ${error.message}`);
|
||||
console.error(error.stack);
|
||||
testPassed = false;
|
||||
resolve('error');
|
||||
}
|
||||
}
|
||||
})();
|
||||
});
|
||||
|
||||
console.log('Waiting for messages...\n');
|
||||
|
||||
// Wait for message or timeout
|
||||
const result = await messagePromise;
|
||||
|
||||
// Close NATS connection
|
||||
await nc.close();
|
||||
console.log('\n✅ NATS connection closed');
|
||||
|
||||
// Final result
|
||||
console.log('\n=== Test Result ===');
|
||||
if (messagesReceived === 0) {
|
||||
console.log('❌ NO MESSAGES RECEIVED');
|
||||
console.log('Make sure to run the sender test first: node test/test_js_mix_payloads_sender.js');
|
||||
process.exit(1);
|
||||
} else if (result === 'error') {
|
||||
console.log('❌ ERROR PROCESSING MESSAGES');
|
||||
process.exit(1);
|
||||
} else if (testPassed) {
|
||||
console.log('✅ ALL TESTS PASSED');
|
||||
process.exit(0);
|
||||
} else {
|
||||
console.log('❌ SOME TESTS FAILED');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Test failed with error:', error.message);
|
||||
console.error(error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
runTest();
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartsend function with mixed payload types
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_SUBJECT = '/test/mix';
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
|
||||
async function runTest() {
|
||||
console.log('=== JavaScript Mix Payloads Sender Test ===\n');
|
||||
|
||||
const correlationId = NATSBridge.uuidv4();
|
||||
const correlationId = crypto.randomUUID();
|
||||
console.log(`Correlation ID: ${correlationId}`);
|
||||
console.log(`Subject: ${TEST_SUBJECT}`);
|
||||
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartreceive function with table (Arrow IPC) payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
|
||||
@@ -42,15 +43,15 @@ async function runTest() {
|
||||
const arrowBuffer = Buffer.from(combined);
|
||||
|
||||
const testData = {
|
||||
correlation_id: 'js-table-receiver-' + Date.now(),
|
||||
msg_id: 'msg-' + Date.now(),
|
||||
correlation_id: 'js-table-receiver-' + crypto.randomUUID(),
|
||||
msg_id: 'msg-' + crypto.randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
send_to: '/test/table',
|
||||
msg_purpose: 'test',
|
||||
sender_name: 'js-table-test',
|
||||
sender_id: 'sender-' + Date.now(),
|
||||
sender_id: 'sender-' + crypto.randomUUID(),
|
||||
receiver_name: 'js-receiver',
|
||||
receiver_id: 'receiver-' + Date.now(),
|
||||
receiver_id: 'receiver-' + crypto.randomUUID(),
|
||||
reply_to: '',
|
||||
reply_to_msg_id: '',
|
||||
broker_url: TEST_BROKER_URL,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartsend function with table (Arrow IPC) payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_SUBJECT = '/test/table';
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
|
||||
async function runTest() {
|
||||
console.log('=== JavaScript Table Sender Test ===\n');
|
||||
|
||||
const correlationId = NATSBridge.uuidv4();
|
||||
const correlationId = crypto.randomUUID();
|
||||
console.log(`Correlation ID: ${correlationId}`);
|
||||
console.log(`Subject: ${TEST_SUBJECT}`);
|
||||
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartreceive function with text payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080';
|
||||
@@ -13,22 +14,22 @@ async function runTest() {
|
||||
|
||||
// Create a mock NATS message with text payload
|
||||
const testData = {
|
||||
correlation_id: 'test-receiver-' + Date.now(),
|
||||
msg_id: 'msg-' + Date.now(),
|
||||
correlation_id: 'test-receiver-' + crypto.randomUUID(),
|
||||
msg_id: 'msg-' + crypto.randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
send_to: '/test/text',
|
||||
msg_purpose: 'test',
|
||||
sender_name: 'js-text-test',
|
||||
sender_id: 'sender-' + Date.now(),
|
||||
sender_id: 'sender-' + crypto.randomUUID(),
|
||||
receiver_name: 'js-receiver',
|
||||
receiver_id: 'receiver-' + Date.now(),
|
||||
receiver_id: 'receiver-' + crypto.randomUUID(),
|
||||
reply_to: '',
|
||||
reply_to_msg_id: '',
|
||||
broker_url: TEST_BROKER_URL,
|
||||
metadata: {},
|
||||
payloads: [
|
||||
{
|
||||
id: 'payload-' + Date.now(),
|
||||
id: 'payload-' + crypto.randomUUID(),
|
||||
dataname: 'message',
|
||||
payload_type: 'text',
|
||||
transport: 'direct',
|
||||
@@ -115,15 +116,15 @@ async function runTest() {
|
||||
// Test with multiple text payloads
|
||||
console.log('\n=== Multiple Text Payloads Test ===');
|
||||
const multiTestData = {
|
||||
correlation_id: 'multi-receiver-' + Date.now(),
|
||||
msg_id: 'msg-' + Date.now(),
|
||||
correlation_id: 'multi-receiver-' + crypto.randomUUID(),
|
||||
msg_id: 'msg-' + crypto.randomUUID(),
|
||||
timestamp: new Date().toISOString(),
|
||||
send_to: '/test/text',
|
||||
msg_purpose: 'test',
|
||||
sender_name: 'js-text-test',
|
||||
sender_id: 'sender-' + Date.now(),
|
||||
sender_id: 'sender-' + crypto.randomUUID(),
|
||||
receiver_name: 'js-receiver',
|
||||
receiver_id: 'receiver-' + Date.now(),
|
||||
receiver_id: 'receiver-' + crypto.randomUUID(),
|
||||
reply_to: '',
|
||||
reply_to_msg_id: '',
|
||||
broker_url: TEST_BROKER_URL,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
* Tests the smartsend function with text payloads
|
||||
*/
|
||||
|
||||
const NATSBridge = require('../src/natbridge.js');
|
||||
const NATSBridge = require('../src/natsbridge.js');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const TEST_SUBJECT = '/test/text';
|
||||
const TEST_BROKER_URL = process.env.NATS_URL || 'nats://localhost:4222';
|
||||
@@ -12,7 +13,7 @@ const TEST_FILESERVER_URL = process.env.FILESERVER_URL || 'http://localhost:8080
|
||||
async function runTest() {
|
||||
console.log('=== JavaScript Text Sender Test ===\n');
|
||||
|
||||
const correlationId = NATSBridge.uuidv4();
|
||||
const correlationId = crypto.randomUUID();
|
||||
console.log(`Correlation ID: ${correlationId}`);
|
||||
console.log(`Subject: ${TEST_SUBJECT}`);
|
||||
console.log(`Broker URL: ${TEST_BROKER_URL}\n`);
|
||||
|
||||
@@ -14,7 +14,7 @@ import base64
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
def run_test():
|
||||
print('=== MicroPython Binary Receiver Test ===\n')
|
||||
|
||||
from natbridge_mpy import _generate_uuid
|
||||
from natsbridge_mpy import _generate_uuid
|
||||
|
||||
# Create mock NATS message with binary payloads
|
||||
image_data = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]) # PNG header
|
||||
|
||||
@@ -13,7 +13,7 @@ import base64
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
|
||||
from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
|
||||
|
||||
TEST_SUBJECT = '/test/binary'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
def run_test():
|
||||
print('=== MicroPython Binary Sender Test ===\n')
|
||||
|
||||
from natbridge_mpy import _generate_uuid
|
||||
from natsbridge_mpy import _generate_uuid
|
||||
correlation_id = 'mpy-binary-test-' + _generate_uuid()
|
||||
print(f'Correlation ID: {correlation_id}')
|
||||
print(f'Subject: {TEST_SUBJECT}')
|
||||
|
||||
@@ -13,7 +13,7 @@ import json
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
def run_test():
|
||||
print('=== MicroPython Dictionary Receiver Test ===\n')
|
||||
|
||||
from natbridge_mpy import _generate_uuid
|
||||
from natsbridge_mpy import _generate_uuid
|
||||
|
||||
# Create a mock NATS message with dictionary payloads
|
||||
import base64
|
||||
|
||||
@@ -13,7 +13,7 @@ import json
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
|
||||
from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
|
||||
|
||||
TEST_SUBJECT = '/test/dictionary'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
@@ -23,7 +23,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
def run_test():
|
||||
print('=== MicroPython Dictionary Sender Test ===\n')
|
||||
|
||||
from natbridge_mpy import _generate_uuid
|
||||
from natsbridge_mpy import _generate_uuid
|
||||
correlation_id = 'mpy-dict-test-' + _generate_uuid()
|
||||
print(f'Correlation ID: {correlation_id}')
|
||||
print(f'Subject: {TEST_SUBJECT}')
|
||||
|
||||
@@ -13,7 +13,7 @@ import json
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge_mpy import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
def run_test():
|
||||
print('=== MicroPython Text Receiver Test ===\n')
|
||||
|
||||
from natbridge_mpy import _generate_uuid
|
||||
from natsbridge_mpy import _generate_uuid
|
||||
|
||||
# Create a mock NATS message with text payload
|
||||
test_text = 'Hello, NATSBridge! This is a test message.'
|
||||
|
||||
@@ -12,7 +12,7 @@ import os
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
|
||||
from natsbridge_mpy import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL, DEFAULT_SIZE_THRESHOLD, MAX_PAYLOAD_SIZE
|
||||
|
||||
TEST_SUBJECT = '/test/text'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
@@ -22,7 +22,7 @@ TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
def run_test():
|
||||
print('=== MicroPython Text Sender Test ===\n')
|
||||
|
||||
from natbridge_mpy import _generate_uuid
|
||||
from natsbridge_mpy import _generate_uuid
|
||||
correlation_id = 'mpy-text-test-' + _generate_uuid()
|
||||
print(f'Correlation ID: {correlation_id}')
|
||||
print(f'Subject: {TEST_SUBJECT}')
|
||||
|
||||
@@ -12,7 +12,7 @@ import base64
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
|
||||
@@ -11,7 +11,7 @@ import base64
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_SUBJECT = '/test/binary'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
|
||||
@@ -11,7 +11,7 @@ import json
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
|
||||
@@ -11,7 +11,7 @@ import json
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_SUBJECT = '/test/dictionary'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
|
||||
@@ -11,7 +11,7 @@ import base64
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_SUBJECT = '/test/mix'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
|
||||
@@ -10,7 +10,7 @@ import os
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_SUBJECT = '/test/table'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
|
||||
@@ -11,7 +11,7 @@ import json
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartreceive, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
TEST_FILESERVER_URL = os.environ.get('FILESERVER_URL', 'http://localhost:8080')
|
||||
|
||||
@@ -10,7 +10,7 @@ import os
|
||||
# Add parent directory to path
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from natbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
from natsbridge import smartsend, DEFAULT_BROKER_URL, DEFAULT_FILESERVER_URL
|
||||
|
||||
TEST_SUBJECT = '/test/text'
|
||||
TEST_BROKER_URL = os.environ.get('NATS_URL', 'nats://localhost:4222')
|
||||
|
||||
Reference in New Issue
Block a user