@@ -60,31 +60,52 @@ public void itSerializesScan() {
6060
6161 @ Test
6262 public void itSerializesRequestAttributes () {
63- Map <String , byte []> requestAttributes =
64- ImmutableMap .< String , byte []> builder () .put ("r " , Bytes .toBytes ("1" )).build ();
63+ Map <String , byte []> requestAttributes = ImmutableMap .< String , byte []> builder ()
64+ . put ( "r" , Bytes . toBytes ( "1" )) .put ("2 " , Bytes .toBytes (0.0 )).build ();
6565 String expectedOutput = "{\n " + " \" startTime\" : 1,\n " + " \" processingTime\" : 2,\n "
6666 + " \" queueTime\" : 3,\n " + " \" responseSize\" : 4,\n " + " \" blockBytesScanned\" : 5,\n "
6767 + " \" multiGetsCount\" : 6,\n " + " \" multiMutationsCount\" : 7,\n "
68- + " \" requestAttributes\" : {\n " + " \" r\" : \" 1\" \n " + " }\n " + "}" ;
68+ + " \" requestAttributes\" : {\n " + " \" r\" : \" 1\" ,\n "
69+ + " \" 2\" : \" \\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\" \n " + " }\n " + "}" ;
6970 OnlineLogRecord o = new OnlineLogRecord (1 , 2 , 3 , 4 , 5 , null , null , null , null , null , null , null ,
7071 6 , 7 , 0 , null , requestAttributes , Collections .emptyMap ());
7172 String actualOutput = o .toJsonPrettyPrint ();
7273 System .out .println (actualOutput );
7374 Assert .assertEquals (actualOutput , expectedOutput );
7475 }
7576
77+ @ Test
78+ public void itOmitsEmptyRequestAttributes () {
79+ OnlineLogRecord o = new OnlineLogRecord (1 , 2 , 3 , 4 , 5 , null , null , null , null , null , null , null ,
80+ 6 , 7 , 0 , null , Collections .emptyMap (), Collections .emptyMap ());
81+ String actualOutput = o .toJsonPrettyPrint ();
82+ System .out .println (actualOutput );
83+ Assert .assertFalse (actualOutput .contains ("requestAttributes" ));
84+ }
85+
7686 @ Test
7787 public void itSerializesConnectionAttributes () {
78- Map <String , byte []> connectionAttributes =
79- ImmutableMap .< String , byte []> builder () .put ("c " , Bytes .toBytes ("1" )).build ();
88+ Map <String , byte []> connectionAttributes = ImmutableMap .< String , byte []> builder ()
89+ . put ( "c" , Bytes . toBytes ( "1" )) .put ("2 " , Bytes .toBytes (0.0 )).build ();
8090 String expectedOutput = "{\n " + " \" startTime\" : 1,\n " + " \" processingTime\" : 2,\n "
8191 + " \" queueTime\" : 3,\n " + " \" responseSize\" : 4,\n " + " \" blockBytesScanned\" : 5,\n "
8292 + " \" multiGetsCount\" : 6,\n " + " \" multiMutationsCount\" : 7,\n "
83- + " \" connectionAttributes\" : {\n " + " \" c\" : \" 1\" \n " + " }\n " + "}" ;
93+ + " \" connectionAttributes\" : {\n "
94+ + " \" 2\" : \" \\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\\ \\ x00\" ,\n "
95+ + " \" c\" : \" 1\" \n " + " }\n " + "}" ;
8496 OnlineLogRecord o = new OnlineLogRecord (1 , 2 , 3 , 4 , 5 , null , null , null , null , null , null , null ,
8597 6 , 7 , 0 , null , Collections .emptyMap (), connectionAttributes );
8698 String actualOutput = o .toJsonPrettyPrint ();
8799 System .out .println (actualOutput );
88100 Assert .assertEquals (actualOutput , expectedOutput );
89101 }
102+
103+ @ Test
104+ public void itOmitsEmptyConnectionAttributes () {
105+ OnlineLogRecord o = new OnlineLogRecord (1 , 2 , 3 , 4 , 5 , null , null , null , null , null , null , null ,
106+ 6 , 7 , 0 , null , Collections .emptyMap (), Collections .emptyMap ());
107+ String actualOutput = o .toJsonPrettyPrint ();
108+ System .out .println (actualOutput );
109+ Assert .assertFalse (actualOutput .contains ("connectionAttributes" ));
110+ }
90111}
0 commit comments