com.carrotsearch.randomizedtesting.NotAnException

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

com.carrotsearch.randomizedtesting.NotAnException

Mark Miller-3
That's just a little funny.

Just started a long run of ChaosMonkeyNothingIsSafeTest and after a while I saw this flash by:

java.lang.IllegalStateException: This Random was created for/by another thread (Thread[TEST-TestScope-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest.testDistribSearch-seed#[2EDBF53611C44F4C],5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest]). Random instances must not be shared (acquire per-thread). Current thread: Thread[Thread-52,5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest]
        at com.carrotsearch.randomizedtesting.AssertingRandom.checkValid(AssertingRandom.java:139)
        at com.carrotsearch.randomizedtesting.AssertingRandom.nextBoolean(AssertingRandom.java:43)
        at org.apache.solr.cloud.ChaosMonkey$1.run(ChaosMonkey.java:353)
Caused by: com.carrotsearch.randomizedtesting.NotAnException: Original allocation stack for this Random (allocated by Thread[TEST-TestScope-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest.testDistribSearch-seed#[2EDBF53611C44F4C],5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest])
        at java.lang.Thread.getStackTrace(Thread.java:1495)
        at com.carrotsearch.randomizedtesting.AssertingRandom.<init>(AssertingRandom.java:33)

I'll look into it. But you've got to love an Exception called NotAnException.

- Mark Miller
lucidimagination.com












---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: com.carrotsearch.randomizedtesting.NotAnException

Yonik Seeley-2-2
Most likely the indexing threads using a base-class method to generate
some random values for a doc?

-Yonik
http://lucidimagination.com


On Sun, Jul 15, 2012 at 9:09 AM, Mark Miller <[hidden email]> wrote:

> That's just a little funny.
>
> Just started a long run of ChaosMonkeyNothingIsSafeTest and after a while I saw this flash by:
>
> java.lang.IllegalStateException: This Random was created for/by another thread (Thread[TEST-TestScope-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest.testDistribSearch-seed#[2EDBF53611C44F4C],5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest]). Random instances must not be shared (acquire per-thread). Current thread: Thread[Thread-52,5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest]
>         at com.carrotsearch.randomizedtesting.AssertingRandom.checkValid(AssertingRandom.java:139)
>         at com.carrotsearch.randomizedtesting.AssertingRandom.nextBoolean(AssertingRandom.java:43)
>         at org.apache.solr.cloud.ChaosMonkey$1.run(ChaosMonkey.java:353)
> Caused by: com.carrotsearch.randomizedtesting.NotAnException: Original allocation stack for this Random (allocated by Thread[TEST-TestScope-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest.testDistribSearch-seed#[2EDBF53611C44F4C],5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest])
>         at java.lang.Thread.getStackTrace(Thread.java:1495)
>         at com.carrotsearch.randomizedtesting.AssertingRandom.<init>(AssertingRandom.java:33)
>
> I'll look into it. But you've got to love an Exception called NotAnException.
>
> - Mark Miller
> lucidimagination.com
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: com.carrotsearch.randomizedtesting.NotAnException

Dawid Weiss
In reply to this post by Mark Miller-3
> That's just a little funny.

Yup. Check out the javadoc:
/**
 * This is never thrown. The only purpose it serves it to carry
chained stack traces
 * for informational purposes.
 */
@SuppressWarnings("serial")
final class NotAnException extends Throwable {

Suggestions on how it could be called better welcome...

> java.lang.IllegalStateException: This Random was created for/by another thread (Thread[TEST-TestScope-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest.testDistribSearch-seed#[2EDBF53611C44F4C],5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest]). Random instances must not be shared (acquire per-thread). Current thread: Thread[Thread-52,5,RandomizedRunner-SuiteThreadGroup-org.apache.solr.cloud.ChaosMonkeyNothingIsSafeTest]

Yes, this is caused by passing Random across threads. If you do this,
it'll cause races for values and make the test evel less reproducible
than it is. There are two solutions:

1) call LTC.random() instead of storing Random in a field (or passing
it down to a subthread); this method creates per-thread random
instances so every thread has its own random sequence.

2) if the above is not possible for some reason you can wrap with a
non-asserting regular Random and share it (not a good idea though):
new Random(random().nextLong()).

> I'll look into it. But you've got to love an Exception called NotAnException.

It's because it's not. It's never thrown from the code and is only
used to provide a stack trace of where the random was allocated, as
the message says. While this may be confusing it help in IDEs a lot
because you can click directly on t he stack trace frames instead of
searching manually for a particular place in the code.

Dawid

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: com.carrotsearch.randomizedtesting.NotAnException

Mark Miller-3

On Jul 15, 2012, at 9:33 AM, Dawid Weiss wrote:

> While this may be confusing it help in IDEs a lot
> because you can click directly on t he stack trace frames instead of
> searching manually for a particular place in the code.

I did not find it confusing per say - the issue was clear by the messaging and pointed exactly where to find the problem.

I guess it would not have told me how I should attempt to fix it - but because I've run into these random to random() changes while merging stuff back before, so it seemed clear enough to me.

But it's still odd to see a stack trace with what looks like an exception called NotAnException. Now that you have pasted the code, it's clear it's not though! It's a Throwable!

I think perhaps there actually would be a better name - but I'm feeling a little lazy to think about it, and it hardly seems that important. And I like a name that gives me a chuckle.

- Mark Miller
lucidimagination.com












---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: com.carrotsearch.randomizedtesting.NotAnException

Dawid Weiss
> pasted the code, it's clear it's not though! It's a Throwable!

See? It's twisted :)

> I think perhaps there actually would be a better name - but I'm feeling a little lazy to think about it, and it hardly seems that important. And I like a name that gives me a chuckle.

It is important in a sense that this is something users should
understand and fix. I freely admit I'm having fun writing this code so
there are more hidden gems like this... I hope you have unicode font
in your console because just recently junit4 says hello to you in
inuktitut (ᐊᐃ)...

Dawid

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]