You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by "jbertram (via GitHub)" <gi...@apache.org> on 2024/02/16 21:26:01 UTC

[PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

jbertram opened a new pull request, #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824

   (no comment)


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1507026878


##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ProducerThread.java:
##########
@@ -190,6 +195,43 @@ protected Message createMessage(long i, String threadName) throws Exception {
 
       answer.setLongProperty("count", i);
       answer.setStringProperty("ThreadSent", threadName);
+
+      if (properties != null && properties.length() != 0) {
+         JsonArray propertyArray = JsonLoader.readArray(new StringReader(properties));
+         for (int j = 0; j < propertyArray.size(); j++) {
+            JsonObject propertyEntry = propertyArray.getJsonObject(j);
+            String type = propertyEntry.getString("type");
+            String key = propertyEntry.getString("key");
+            String value = propertyEntry.getString("value");
+            switch (type) {
+               case "boolean":
+                  answer.setBooleanProperty(key, Boolean.parseBoolean(value));
+                  break;
+               case "int":
+                  answer.setIntProperty(key, Integer.parseInt(value));
+                  break;
+               case "long":
+                  answer.setLongProperty(key, Long.parseLong(value));
+                  break;
+               case "byte":
+                  answer.setByteProperty(key, Byte.parseByte(value));
+                  break;
+               case "short":
+                  answer.setShortProperty(key, Short.parseShort(value));
+                  break;
+               case "float":
+                  answer.setFloatProperty(key, Float.parseFloat(value));
+                  break;
+               case "double":
+                  answer.setDoubleProperty(key, Double.parseDouble(value));
+                  break;
+               case "string":
+                  answer.setStringProperty(key, value);
+                  break;
+            }

Review Comment:
   Done. I also added a new test to make sure incorrect types are dealt with properly.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1517099610


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I like the idea of unit tests vs. integration tests so I implemented that.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1503959087


##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/ProducerThread.java:
##########
@@ -190,6 +195,43 @@ protected Message createMessage(long i, String threadName) throws Exception {
 
       answer.setLongProperty("count", i);
       answer.setStringProperty("ThreadSent", threadName);
+
+      if (properties != null && properties.length() != 0) {
+         JsonArray propertyArray = JsonLoader.readArray(new StringReader(properties));
+         for (int j = 0; j < propertyArray.size(); j++) {
+            JsonObject propertyEntry = propertyArray.getJsonObject(j);
+            String type = propertyEntry.getString("type");
+            String key = propertyEntry.getString("key");
+            String value = propertyEntry.getString("value");
+            switch (type) {
+               case "boolean":
+                  answer.setBooleanProperty(key, Boolean.parseBoolean(value));
+                  break;
+               case "int":
+                  answer.setIntProperty(key, Integer.parseInt(value));
+                  break;
+               case "long":
+                  answer.setLongProperty(key, Long.parseLong(value));
+                  break;
+               case "byte":
+                  answer.setByteProperty(key, Byte.parseByte(value));
+                  break;
+               case "short":
+                  answer.setShortProperty(key, Short.parseShort(value));
+                  break;
+               case "float":
+                  answer.setFloatProperty(key, Float.parseFloat(value));
+                  break;
+               case "double":
+                  answer.setDoubleProperty(key, Double.parseDouble(value));
+                  break;
+               case "string":
+                  answer.setStringProperty(key, value);
+                  break;
+            }

Review Comment:
   This is missing a default case, which would be useful for when someone inevitably typos the type name, or just uses e.g the proper class name such as String (could also just handle that one by lower-casing the type before).



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1507347730


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +91,138 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'boolean','key':'myTrueBoolean','value':'true'},{'type':'boolean','key':'myFalseBoolean','value':'false'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myTrueBoolean"));
+      Assert.assertTrue(m.getBooleanProperty("myTrueBoolean"));
+      Assert.assertTrue(m.propertyExists("myFalseBoolean"));
+      Assert.assertFalse(m.getBooleanProperty("myFalseBoolean"));
+   }
+
+   @Test
+   public void testIntMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myInt"));
+      Assert.assertEquals(Integer.MAX_VALUE, m.getIntProperty("myInt"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testLongMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myLong"));
+      Assert.assertEquals(Long.MAX_VALUE, m.getLongProperty("myLong"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testByteMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'byte','key':'myByte','value':'127'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myByte"));
+      Assert.assertEquals((byte) 127, m.getByteProperty("myByte"));
+
+      assertEquals(0L, produceMessages(address, null, 1, "[{'type':'byte','key':'myByte','value':'128'}]".replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testShortMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myShort"));
+      Assert.assertEquals(Short.MAX_VALUE, m.getShortProperty("myShort"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testFloatMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'float','key':'myFloat','value':'" + Float.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myFloat"));
+      Assert.assertEquals(Float.MAX_VALUE, m.getFloatProperty("myFloat"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'float','key':'myFloat','value':'badFloat'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testDoubleMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'double','key':'myDouble','value':'" + Double.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myDouble"));
+      Assert.assertEquals(Double.MAX_VALUE, m.getDoubleProperty("myDouble"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'double','key':'myDouble','value':'badDouble'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testStringMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'string','key':'myString','value':'foo'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myString"));
+      Assert.assertEquals("foo", m.getStringProperty("myString"));
+   }
+
+   @Test
+   public void testBadMessageProperties() throws Exception {
+      PrintStream originalErr = System.err;
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      PrintStream newErr = new PrintStream(baos);
+      System.setErr(newErr);
+      try {
+         produceMessages("test", null, 1, "[{'type':'myType','key':'myKey','value':'myValue'}]".replaceAll("'", "\""));
+         assertEquals("Unable to set property: myKey. Did not recognize type: myType. Supported types are: boolean, int, long, byte, short, float, double, string.\n", baos.toString());
+      } finally {
+         System.setErr(originalErr);
+      }

Review Comment:
   Ick on messing with the System. I believe most of the regular artemis CLI commands have a 'context' of some kind thats used for the output, which allows testing the output without this kind of hack. Doesnt the Producer?



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr merged PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "clebertsuconic (via GitHub)" <gi...@apache.org>.
clebertsuconic commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1503463316


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   can't you make a single test testMessageProperties... have multiple messages (or maybe just one) and validate them all in a single test?



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1506995772


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   Yes. I could combine all the independent property tests into a single test. However, it's not clear to me what benefit that would provide.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1518092787


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I actually attempted to use a mock to begin with but wasn't familiar enough (or patient enough) to get it working. Thanks for the commit. I've squashed and pushed.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "clebertsuconic (via GitHub)" <gi...@apache.org>.
clebertsuconic commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1503462284


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -54,9 +54,11 @@ public void tearDown() throws Exception {
       super.tearDown();
    }
 
-   private void produceMessages(String address, String message, int msgCount) throws Exception {
-      new Producer()
+   private Object produceMessages(String address, String message, int msgCount, String properties) throws Exception {
+      System.out.println(properties);

Review Comment:
   I wouldn't use System.out.println here.. would keep logger.debug



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#issuecomment-1970430201

   @gemmellr, yes, I do think that's a worthy improvement for the consumer. I opened [ARTEMIS-4659](https://issues.apache.org/jira/browse/ARTEMIS-4659) for this.


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1516911181


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I consolidated all the individual tests into one.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1516682947


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +91,138 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'boolean','key':'myTrueBoolean','value':'true'},{'type':'boolean','key':'myFalseBoolean','value':'false'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myTrueBoolean"));
+      Assert.assertTrue(m.getBooleanProperty("myTrueBoolean"));
+      Assert.assertTrue(m.propertyExists("myFalseBoolean"));
+      Assert.assertFalse(m.getBooleanProperty("myFalseBoolean"));
+   }
+
+   @Test
+   public void testIntMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myInt"));
+      Assert.assertEquals(Integer.MAX_VALUE, m.getIntProperty("myInt"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testLongMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myLong"));
+      Assert.assertEquals(Long.MAX_VALUE, m.getLongProperty("myLong"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testByteMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'byte','key':'myByte','value':'127'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myByte"));
+      Assert.assertEquals((byte) 127, m.getByteProperty("myByte"));
+
+      assertEquals(0L, produceMessages(address, null, 1, "[{'type':'byte','key':'myByte','value':'128'}]".replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testShortMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myShort"));
+      Assert.assertEquals(Short.MAX_VALUE, m.getShortProperty("myShort"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testFloatMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'float','key':'myFloat','value':'" + Float.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myFloat"));
+      Assert.assertEquals(Float.MAX_VALUE, m.getFloatProperty("myFloat"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'float','key':'myFloat','value':'badFloat'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testDoubleMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'double','key':'myDouble','value':'" + Double.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myDouble"));
+      Assert.assertEquals(Double.MAX_VALUE, m.getDoubleProperty("myDouble"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'double','key':'myDouble','value':'badDouble'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testStringMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'string','key':'myString','value':'foo'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myString"));
+      Assert.assertEquals("foo", m.getStringProperty("myString"));
+   }
+
+   @Test
+   public void testBadMessageProperties() throws Exception {
+      PrintStream originalErr = System.err;
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      PrintStream newErr = new PrintStream(baos);
+      System.setErr(newErr);
+      try {
+         produceMessages("test", null, 1, "[{'type':'myType','key':'myKey','value':'myValue'}]".replaceAll("'", "\""));
+         assertEquals("Unable to set property: myKey. Did not recognize type: myType. Supported types are: boolean, int, long, byte, short, float, double, string.\n", baos.toString());
+      } finally {
+         System.setErr(originalErr);
+      }

Review Comment:
   Done.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1516682947


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +91,138 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'boolean','key':'myTrueBoolean','value':'true'},{'type':'boolean','key':'myFalseBoolean','value':'false'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myTrueBoolean"));
+      Assert.assertTrue(m.getBooleanProperty("myTrueBoolean"));
+      Assert.assertTrue(m.propertyExists("myFalseBoolean"));
+      Assert.assertFalse(m.getBooleanProperty("myFalseBoolean"));
+   }
+
+   @Test
+   public void testIntMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myInt"));
+      Assert.assertEquals(Integer.MAX_VALUE, m.getIntProperty("myInt"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'int','key':'myInt','value':'" + Integer.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testLongMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myLong"));
+      Assert.assertEquals(Long.MAX_VALUE, m.getLongProperty("myLong"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'long','key':'myLong','value':'" + Long.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testByteMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'byte','key':'myByte','value':'127'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myByte"));
+      Assert.assertEquals((byte) 127, m.getByteProperty("myByte"));
+
+      assertEquals(0L, produceMessages(address, null, 1, "[{'type':'byte','key':'myByte','value':'128'}]".replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testShortMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myShort"));
+      Assert.assertEquals(Short.MAX_VALUE, m.getShortProperty("myShort"));
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'short','key':'myShort','value':'" + Short.MAX_VALUE + 1 + "'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testFloatMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'float','key':'myFloat','value':'" + Float.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myFloat"));
+      Assert.assertEquals(Float.MAX_VALUE, m.getFloatProperty("myFloat"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'float','key':'myFloat','value':'badFloat'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testDoubleMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, ("[{'type':'double','key':'myDouble','value':'" + Double.MAX_VALUE + "'}]").replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myDouble"));
+      Assert.assertEquals(Double.MAX_VALUE, m.getDoubleProperty("myDouble"), 0.0);
+
+      assertEquals(0L, produceMessages(address, null, 1, ("[{'type':'double','key':'myDouble','value':'badDouble'}]").replaceAll("'", "\"")));
+   }
+
+   @Test
+   public void testStringMessageProperties() throws Exception {
+      Message m;
+      String address = "test";
+      Session session = createSession(connection);
+
+      assertEquals(1L, produceMessages(address, null, 1, "[{'type':'string','key':'myString','value':'foo'}]".replaceAll("'", "\"")));
+
+      m = consumeMessages(session, address, 1).get(0);
+      Assert.assertTrue(m.propertyExists("myString"));
+      Assert.assertEquals("foo", m.getStringProperty("myString"));
+   }
+
+   @Test
+   public void testBadMessageProperties() throws Exception {
+      PrintStream originalErr = System.err;
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      PrintStream newErr = new PrintStream(baos);
+      System.setErr(newErr);
+      try {
+         produceMessages("test", null, 1, "[{'type':'myType','key':'myKey','value':'myValue'}]".replaceAll("'", "\""));
+         assertEquals("Unable to set property: myKey. Did not recognize type: myType. Supported types are: boolean, int, long, byte, short, float, double, string.\n", baos.toString());
+      } finally {
+         System.setErr(originalErr);
+      }

Review Comment:
   The `ProducerThread` logs directly using `System`. I sent #4846 to fix this. Once that's merged I'll update this test.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1507323452


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I'd guess that Clebert was just thinking about it starting X brokers and making X connections, sessions, producers, consumers currently to test something carried on the message alone that could still be done with 1 of each.
   
   I tend to prefer more granular tests. Although, I'd personally go further and think the CLI bits could probably have been unit tested without any broker etc since its just a case of verifying the arg is decoded as expected, and ensuring things are set as expected on the message before it is sent...the clients sending of a message with props is covered elsewhere already)



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1517786516


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I pushed another commit that switches the unit tests to be more granular as with the original tests, and use a mocked message that gets rid of the large test impl More succinct, and verifies just the ProducerThread behaviour rather than also testing the test-msg-impl as the prior tests were really doing.
   
   I also restored a basic integration test, since ProducerThreadTest doesnt really cover that the option is actually entirely wired through correctly and is effective in practice, and cant really without heavily reworking Producer+ProducerThread so that a unit test really could verify things from initial command to the point of 'this message is whats about to be sent' without still standing up the broker + producer etc.
   
   If you like the changes, just squash them and push...



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1519678085


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I actually meant push to main since I already reviewed them, should have been more specific given the context hehe, woops. Merged now :)



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#issuecomment-1966203995

   Related question. Does adding the ability to send properties, perhaps also suggest there would be utility in having the option for the CLI consumer to print such properties? E.g either print all, or specifically specified ones.


-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1507027552


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -54,9 +54,11 @@ public void tearDown() throws Exception {
       super.tearDown();
    }
 
-   private void produceMessages(String address, String message, int msgCount) throws Exception {
-      new Producer()
+   private Object produceMessages(String address, String message, int msgCount, String properties) throws Exception {
+      System.out.println(properties);

Review Comment:
   I forgot to remove that.



-- 
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: gitbox-unsubscribe@activemq.apache.org

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


Re: [PR] ARTEMIS-4648 support typed properties from CLI producer [activemq-artemis]

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4824:
URL: https://github.com/apache/activemq-artemis/pull/4824#discussion_r1507323452


##########
artemis-cli/src/test/java/org/apache/activemq/cli/test/CliProducerTest.java:
##########
@@ -88,6 +90,124 @@ public void testSendMessage() throws Exception {
       checkSentMessages(session, address, null);
    }
 
+   @Test
+   public void testBooleanMessageProperties() throws Exception {

Review Comment:
   I'd guess that Clebert was just thinking about it starting X brokers and making X connections, sessions, producers currently to test something carried on the message alone that could still be done with 1 of each.
   
   I tend to prefer more granular tests. Although, I'd personally go further and think the CLI bits could probably have been unit tested without any broker etc since its just a case of verifying the arg is decoded as expected, and ensuring things are set as expected on the message before it is sent...the clients sending of a message with props is covered elsewhere already)



-- 
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: gitbox-unsubscribe@activemq.apache.org

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