Discord4J / Stores

A set of Discord entity cache implementations for Discord4J
https://discord4j.com
GNU Lesser General Public License v3.0
11 stars 7 forks source link

StoreTCK inconsistently throws OutOfMemoryError #10

Closed W1sh closed 3 years ago

W1sh commented 3 years ago

While trying to test an implementation of a store in Hazelcast I can't run the StoreTCK tests consistently as most of the time I get OutOfMemoryError, see below:

java.lang.OutOfMemoryError: Java heap space
    at discord4j.store.tck.StoreTCK.randomizeObject(StoreTCK.java:107)
    at discord4j.store.tck.StoreTCK.randomBean(StoreTCK.java:139)
    at discord4j.store.tck.StoreTCK.testSerialization(StoreTCK.java:223)
    at discord4j.store.tck.StoreTCK.lambda$tckEntryPoint$0(StoreTCK.java:155)
    at discord4j.store.tck.StoreTCK$$Lambda$56/0x0000000800ba3040.run(Unknown Source)
    at discord4j.store.tck.StoreTCK.safeTest(StoreTCK.java:203)
    at discord4j.store.tck.StoreTCK.tckEntryPoint(StoreTCK.java:155)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
10:58:12.480 [main] INFO org.w1sh.dusa.hazelcast.HazelcastStoreServiceTest - Long-Object stores disabled.
10:58:12.480 [main] ERROR org.w1sh.dusa.hazelcast.HazelcastStoreServiceTest - 0/1 tests passed.
10:58:12.480 [main] ERROR org.w1sh.dusa.hazelcast.HazelcastStoreServiceTest - It is possible the store can still work with Discord4J, but support is not guaranteed! 

After doing just a quick check on the code I believe it is due to this piece of code:

int arrLen = rng.nextInt(Integer.MAX_VALUE - 5);
long[] arr = new long[arrLen];

Seems that this allocation most of the time will exceed the max memory allowed as an array with sometimes millions of positions is a bit too much.

quanticc commented 3 years ago

Thanks. @austinv11 do you have time to look at this?

austinv11 commented 3 years ago

c5b4712 should fix it. @W1sh you might want to verify that this is the case on your system