Browse Source

extra test pkg

Enzo 1 year ago
parent
commit
17b1258058
3 changed files with 47 additions and 1 deletions
  1. 2 1
      package.json
  2. 17 0
      test/hero.proto
  3. 28 0
      test/testGrpc.ts

+ 2 - 1
package.json

@@ -15,7 +15,8 @@
     "publish": "node test/publisher.js",
     "publish": "node test/publisher.js",
     "consume": "node --max-old-space-size=512 test/consumer_1.js",
     "consume": "node --max-old-space-size=512 test/consumer_1.js",
     "buffer": "node test/buffer_showcase.js",
     "buffer": "node test/buffer_showcase.js",
-    "schedule": "node test/scheduler_showcase.js"
+    "schedule": "node test/scheduler_showcase.js",
+    "grpc": "node test/testGrpc.js"
   },
   },
   "repository": {
   "repository": {
     "type": "git",
     "type": "git",

+ 17 - 0
test/hero.proto

@@ -0,0 +1,17 @@
+syntax = "proto3";
+
+package hero;
+
+service HeroService {
+  rpc FindOne (HeroById) returns (Hero);
+  rpc FindMany (stream HeroById) returns (stream Hero);
+}
+
+message HeroById {
+  int32 id = 1;
+}
+
+message Hero {
+  int32 id = 1;
+  string name = 2;
+}

+ 28 - 0
test/testGrpc.ts

@@ -0,0 +1,28 @@
+const grpc = require('grpc');
+const protoLoader = require('@grpc/proto-loader');
+
+// Load the gRPC service definition
+const packageDefinition = protoLoader.loadSync('C:/Users/esenz/dev/Task/Fis-SearchUtility/test/hero.proto');
+const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
+
+// Create a gRPC client instance
+const heroServiceClient = new protoDescriptor.hero.HeroService(
+    'http://192.168.100.32:3001/', // Replace with your server address and port
+    grpc.credentials.createInsecure()
+);
+
+// Create the gRPC request object
+const request = {
+    id: 1, // Replace with the desired hero ID
+};
+
+// Send the gRPC request
+heroServiceClient.FindOne(request, (error, response) => {
+    if (error) {
+        console.error('Error:', error);
+        return;
+    }
+
+    // Handle the response
+    console.log('Response:', response);
+});