sashapolo commented on a change in pull request #153:
URL: https://github.com/apache/ignite-3/pull/153#discussion_r643159735
##########
File path:
modules/network/src/test/java/org/apache/ignite/network/internal/AllTypesMessageGenerator.java
##########
@@ -81,139 +79,142 @@ public static AllTypesMessage generate(long seed, boolean
nestedMsg) {
* Generate random value.
*
* @param random Seeded random.
- * @param type Value type.
+ * @param field Field which value is being generated.
* @param nestedMsg {@code true} if nested messages should be generated,
{@code false} otherwise.
* @return Random value.
- * @throws Exception If failed.
*/
- private static Object randomValue(Random random, MessageCollectionItemType
type, boolean nestedMsg) throws Exception {
- switch (type) {
- case BYTE:
- return (byte) random.nextInt();
-
- case SHORT:
- return (short) random.nextInt();
-
- case INT:
- return random.nextInt();
-
- case LONG:
- return random.nextLong();
-
- case FLOAT:
- return random.nextFloat();
-
- case DOUBLE:
- return random.nextDouble();
-
- case CHAR:
- return (char) random.nextInt();
-
- case BOOLEAN:
- return random.nextBoolean();
-
- case BYTE_ARR:
- int byteArrLen = random.nextInt(1024);
- byte[] bytes = new byte[byteArrLen];
- random.nextBytes(bytes);
- return bytes;
-
- case SHORT_ARR:
- int shortArrLen = random.nextInt(1024);
- short[] shorts = new short[1024];
- for (int i = 0; i < shortArrLen; i++) {
- shorts[i] = (short) random.nextInt();
- }
- return shorts;
-
- case INT_ARR:
- int intArrLen = random.nextInt(1024);
- int[] ints = new int[1024];
- for (int i = 0; i < intArrLen; i++) {
- ints[i] = random.nextInt();
- }
- return ints;
-
- case LONG_ARR:
- int longArrLen = random.nextInt(1024);
- long[] longs = new long[1024];
- for (int i = 0; i < longArrLen; i++) {
- longs[i] = random.nextLong();
- }
- return longs;
+ @Nullable
+ private static Object randomValue(Random random, Field field, boolean
nestedMsg) {
+ Class<?> type = field.getType();
- case FLOAT_ARR:
- int floatArrLen = random.nextInt(1024);
- float[] floats = new float[1024];
- for (int i = 0; i < floatArrLen; i++) {
- floats[i] = random.nextFloat();
- }
- return floats;
-
- case DOUBLE_ARR:
- int doubleArrLen = random.nextInt(1024);
- double[] doubles = new double[1024];
- for (int i = 0; i < doubleArrLen; i++) {
- doubles[i] = random.nextDouble();
- }
- return doubles;
-
- case CHAR_ARR:
- int charArrLen = random.nextInt(1024);
- char[] chars = new char[1024];
- for (int i = 0; i < charArrLen; i++) {
- chars[i] = (char) random.nextInt();
- }
- return chars;
-
- case BOOLEAN_ARR:
- int booleanArrLen = random.nextInt(1024);
- boolean[] booleans = new boolean[1024];
- for (int i = 0; i < booleanArrLen; i++) {
- booleans[i] = random.nextBoolean();
- }
- return booleans;
-
- case STRING:
- int aLetter = 'a';
- int strLen = random.nextInt(1024);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < strLen; i++) {
- int letter = aLetter + random.nextInt(26);
- sb.append(letter);
- }
- return sb.toString();
-
- case BIT_SET:
- BitSet set = new BitSet();
- int setLen = random.nextInt(10);
- for (int i = 0; i < setLen; i++) {
- if (random.nextBoolean()) {
- set.set(i);
- }
- }
-
- return set;
-
- case UUID:
- byte[] uuidBytes = new byte[16];
- random.nextBytes(uuidBytes);
- return UUID.nameUUIDFromBytes(uuidBytes);
+ if (type == byte.class) {
+ return (byte) random.nextInt();
+ }
Review comment:
Is this rule obligatory in ignite 3? I can see both styles at the moment
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]