yifan-c commented on code in PR #47:
URL: https://github.com/apache/cassandra-sidecar/pull/47#discussion_r1220062467


##########
src/main/java/org/apache/cassandra/sidecar/MainModule.java:
##########
@@ -304,4 +314,28 @@ public ChecksumVerifier checksumVerifier(Vertx vertx)
     {
         return new MD5ChecksumVerifier(vertx.fileSystem());
     }
+
+    @Provides
+    @Singleton
+    @Named("SidecarVersion")
+    private static String sidecarVersion()
+    {
+        final String resource = "/sidecar.version";
+        try (InputStream input = 
NodeSettings.class.getResourceAsStream(resource);
+             ByteArrayOutputStream output = new ByteArrayOutputStream())
+        {
+            byte[] buffer = new byte[32];
+            int length;
+            while ((length = input.read(buffer)) >= 0)
+            {
+                output.write(buffer, 0, length);
+            }
+            return output.toString(StandardCharsets.UTF_8.name());
+        }
+        catch (Exception exception)
+        {
+            LOGGER.error("Failed to retrieve Sidecar version", exception);
+        }
+        return "unknown";
+    }

Review Comment:
   Regarding the test, you can add a *test* resource called `sidecar.version`, 
and write a testing like this.
   
   ```java
       @Test
       public void testReadSidecarVersion()
       {
           String version = injector.getInstance(Key.get(String.class, 
Names.named("SidecarVersion")));
           Assertions.assertThat(version).isNotNull().isEqualTo("1.0.0");
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to