Skip to content

Commit 51878c2

Browse files
mukundansundartanvigour
authored andcommitted
Test long vals (#717)
* run IT test for long values Signed-off-by: tanvigour <[email protected]> * Fix the class name Signed-off-by: tanvigour <[email protected]> * assert for all messages and fix class name Signed-off-by: tanvigour <[email protected]> * test for Long.MAX_VALUE Signed-off-by: tanvigour <[email protected]> * revert back long number and print Signed-off-by: tanvigour <[email protected]> * fix the typo Signed-off-by: tanvigour <[email protected]> * update the latest dapr commit in workflow files Signed-off-by: tanvigour <[email protected]> * log some more data to debug Signed-off-by: tanvigour <[email protected]> * debug Signed-off-by: tanvigour <[email protected]> * get the value from messages Signed-off-by: tanvigour <[email protected]> * fix long values assert Signed-off-by: Mukundan Sundararajan <[email protected]> * increasing TTL Signed-off-by: Mukundan Sundararajan <[email protected]> Co-authored-by: tanvigour <[email protected]> Co-authored-by: tanvigour <[email protected]>
1 parent 940ee97 commit 51878c2

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

sdk-tests/src/test/java/io/dapr/it/pubsub/http/PubSubIT.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import io.dapr.serializer.DaprObjectSerializer;
2727
import io.dapr.utils.TypeRef;
2828
import org.junit.After;
29+
import org.junit.Assert;
2930
import org.junit.Test;
3031
import org.junit.runner.RunWith;
3132
import org.junit.runners.Parameterized;
@@ -35,12 +36,13 @@
3536
import java.util.Arrays;
3637
import java.util.Collection;
3738
import java.util.Collections;
38-
import java.util.LinkedHashMap;
39-
import java.util.List;
40-
import java.util.Random;
4139
import java.util.HashSet;
4240
import java.util.Iterator;
41+
import java.util.LinkedHashMap;
42+
import java.util.List;
4343
import java.util.Objects;
44+
import java.util.Random;
45+
import java.util.Set;
4446

4547
import static io.dapr.it.Retry.callWithRetry;
4648
import static io.dapr.it.TestUtils.assertThrowsDaprException;
@@ -426,29 +428,27 @@ public void testLongValues() throws Exception {
426428
daprRun.switchToHTTP();
427429
}
428430

429-
ConvertToLong toLong = new ConvertToLong();
430-
HashSet<ConvertToLong> expected = new HashSet<>();
431-
Random random = new Random();
432-
Long randomLong = 590518626939830271L;
433-
random.setSeed(randomLong);
434-
toLong.setValue(randomLong);
435-
expected.add(toLong);
436-
for (int i = 1; i < NUM_MESSAGES; i++) {
437-
ConvertToLong value = new ConvertToLong();
438-
randomLong = random.nextLong();
439-
value.setValue(randomLong);
440-
expected.add(value);
441-
System.out.println("expected value is : " +value);
431+
Random random = new Random(590518626939830271L);
432+
Set<ConvertToLong> values = new HashSet<>();
433+
values.add(new ConvertToLong().setVal(590518626939830271L));
434+
ConvertToLong val;
435+
for (int i = 0; i < NUM_MESSAGES - 1; i++) {
436+
do {
437+
val = new ConvertToLong().setVal(random.nextLong());
438+
} while (values.contains(val));
439+
values.add(val);
442440
}
443-
Iterator expectVal = expected.iterator();
441+
Iterator<ConvertToLong> valuesIt = values.iterator();
444442
try (DaprClient client = new DaprClientBuilder().build()) {
445-
while(expectVal.hasNext()) {
443+
for (int i = 0; i < NUM_MESSAGES; i++) {
444+
ConvertToLong value = valuesIt.next();
445+
System.out.println("The long value sent " + value.getValue());
446446
//Publishing messages
447447
client.publishEvent(
448448
PUBSUB_NAME,
449449
LONG_TOPIC_NAME,
450-
expectVal.next(),
451-
Collections.singletonMap(Metadata.TTL_IN_SECONDS, "1")).block();
450+
value,
451+
Collections.singletonMap(Metadata.TTL_IN_SECONDS, "30")).block();
452452

453453
try {
454454
Thread.sleep((long) (1000 * Math.random()));
@@ -460,7 +460,7 @@ public void testLongValues() throws Exception {
460460
}
461461
}
462462

463-
HashSet<ConvertToLong> actual = new HashSet<>();
463+
Set<ConvertToLong> actual = new HashSet<>();
464464
try (DaprClient client = new DaprClientBuilder().build()) {
465465
callWithRetry(() -> {
466466
System.out.println("Checking results for topic " + LONG_TOPIC_NAME);
@@ -469,12 +469,12 @@ public void testLongValues() throws Exception {
469469
"messages/testinglongvalues",
470470
null,
471471
HttpExtension.GET, CLOUD_EVENT_LONG_LIST_TYPE_REF).block();
472-
assertNotNull(messages);
473-
for (int i = 0; i < NUM_MESSAGES; i++) {
474-
actual.add(messages.get(i).getData());
472+
Assert.assertNotNull(messages);
473+
for (CloudEvent<ConvertToLong> message : messages) {
474+
actual.add(message.getData());
475475
}
476-
assertEquals(expected,actual);
477476
}, 2000);
477+
Assert.assertEquals(values, actual);
478478
}
479479
}
480480

@@ -493,15 +493,17 @@ public void setId(String id) {
493493
public static class ConvertToLong {
494494
private Long value;
495495

496+
public ConvertToLong setVal(Long value) {
497+
this.value = value;
498+
return this;
499+
}
500+
496501
public Long getValue() {
497502
return value;
498503
}
499504

500-
public void setValue(Long value) {
501-
this.value = value;
502-
}
503505

504-
@Override
506+
@Override
505507
public boolean equals(Object o) {
506508
if (this == o) return true;
507509
if (o == null || getClass() != o.getClass()) return false;

0 commit comments

Comments
 (0)