[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-23 Thread Gus Power (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15600144#comment-15600144
 ] 

Gus Power commented on LANG-1196:
-

Yes from a thread-safety point of view your patch of just setting the seed on 
the underlying random is definitely better. The stock Random.setSeed(seed) 
method is synchronized and so shouldn't need an explicit lock. I guess a 
possible alternative is to pass in a Random but it there are already plenty of 
randomX() style methods on there and I didn't want to create more.

I broke out the Scenario class to better understand what was happening in the 
random generation. I wasn't immediately obvious to me that it walks backwards 
through the character array, shuttling forward a step if it happens upon a 
surrogate character and it's at the first element. In this instance I was 
trying to determine whether it's a bug to allow odd numbers of characters when 
requesting UTF-16 surrogate pairs. The Scenario class passes all the units 
tests without change so it should be functionally equivalent to the existing 
implementation. 

> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
> Attachments: LANG-1196.patch
>
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-15 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15577998#comment-15577998
 ] 

Bruno P. Kinoshita commented on LANG-1196:
--

>>new Scenario object
>
>Does it belong in this report?

It is about a new static class added with name Scenario, and a few methods like 
#generate(), #run(), #inProgress(), etc. Didn't have time to review it.

But I'm finding it quite hard to find a design that will achieve certain 
immutability, and also allowing to set a different seed or random number 
generator. Not without changing a few things; and possibly breaking backward 
compatibility.

I think we can either write a new class with the desired behaviour and 
characteristics, or work on the new component that could maintain a new 
RandomStringUtils.

> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
> Attachments: LANG-1196.patch
>
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-14 Thread Gilles (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15576968#comment-15576968
 ] 

Gilles commented on LANG-1196:
--

{quote}
{code}
public static void seed(long seed) {
RANDOM = new Random(seed);
}
{code}
This could cause race conditions
{quote}
I'd think so too.

If you assume that the generator is the JDK's {{Random}} class, the following 
is probably slightly better:
{code}
public static void seed(long seed) {
RANDOM.setSeed(seed);
}
{code}

But it still could cause trouble if multiple threads want to call 
{{seed(long)}}.

bq. I think we would either have to rewrite with a different design

I believe so.

bq. adding a few more that receive a Random object?

Possible, but the mixed API would be confusing.

bq. new Scenario object

Does it belong in this report?

> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
> Attachments: LANG-1196.patch
>
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-14 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15576851#comment-15576851
 ] 

Bruno P. Kinoshita commented on LANG-1196:
--

Thanks for providing a patch so quickly.

{code}
public static void seed(long seed) {
RANDOM = new Random(seed);
}
{code}

This could cause race conditions, where one thread could call a method to 
generate a random, while another user modifies the same instance of Random.

I suggested returning a new instance, kind like a Builder object, but all the 
methods are static, and it would be at least weird to create an instance to 
call the static methods, that also access at least one static member. That 
could create new problems. I think we would either have to rewrite with a 
different design, or keep it as static methods, but perhaps adding a few more 
that receive a Random object? WDYT?

Cannot really review the new Scenario object without more time to read and 
understand the other changes, but maybe someone else could chime in and take a 
look on it.

Thanks again!
Bruno

> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
> Attachments: LANG-1196.patch
>
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-14 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15574521#comment-15574521
 ] 

Bruno P. Kinoshita commented on LANG-1196:
--

>RandomSringUtils is a "utility" class: all methods are static. Passing an 
>argument to the constructor will require to remove the static keyword, which 
>is not a compatible change.

Ack. Though an alternative could be also include an extra static builder, that 
would call a hidden constructor passing a different Random generator.

>Better would be to define a specific interface (as suggested by Jochen on the 
>ML).

Agreed :-)

>Even better would be to have a dedicated Commons component (for random-related 
>utilities).

I'm lurking there and reading the threads on the RNG spinf off from CM. Waiting 
for a few days (or maybe weeks?) vacation to have fun learning prng, rng, etc. 
But this would be my favorite option.

Unless this issue gets a pull request, patch, or other suggestions, I'll leave 
it as is for now. Thanks Gilles.



> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-12 Thread Gilles (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15568822#comment-15568822
 ] 

Gilles commented on LANG-1196:
--

bq. easy fix would be to pass the Random implementation in the constructor

{{RandomSringUtils}} is a "_utility_" class: all methods are static. Passing an 
argument to the constructor will require to remove the _static_ keyword, which 
is not a compatible change.

Better would be to define a specific interface (as suggested by Jochen on the 
ML).

Even better would be to have a dedicated Commons component (for random-related 
utilities).
There is a willingness to create one based on the RNG interface defined in
  
http://commons.apache.org/proper/commons-rng/apidocs/org/apache/commons/rng/UniformRandomProvider.html

Please have a look at the "dev" ML archive for recent discussions about the new 
"RNG" component.


> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (LANG-1196) Provide way to set random number generator on RandomStringUtils to enable repeatable test execution

2016-10-12 Thread Bruno P. Kinoshita (JIRA)

[ 
https://issues.apache.org/jira/browse/LANG-1196?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15568166#comment-15568166
 ] 

Bruno P. Kinoshita commented on LANG-1196:
--

Hi Gus,

Having a patch or pull request would definitely help reviewing your use case. I 
had a quick look at RandomStringUtils, and one easy fix would be to pass the 
Random implementation in the constructor. But java.util.Random inherits only 
form Object. Perhaps another object that wraps different random number 
generators? Feel free to update the ticket with comments or a patch or link to 
a pull request or repository.

Cheers
Bruno 

> Provide way to set random number generator on RandomStringUtils to enable 
> repeatable test execution
> ---
>
> Key: LANG-1196
> URL: https://issues.apache.org/jira/browse/LANG-1196
> Project: Commons Lang
>  Issue Type: Improvement
>  Components: lang.*
>Affects Versions: 3.4
> Environment: java version "1.8.0_66"
> Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
> Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
> Linux 4.0.5 #3 SMP Mon Sep 14 12:41:09 BST 2015 x86_64 Intel(R) Core(TM) 
> i7-4710MQ CPU @ 2.50GHz GenuineIntel GNU/Linux
>Reporter: Gus Power
>Priority: Minor
>
> Hi,
> I'm using [Sham 
> |http://search.maven.org/#artifactdetails%7Corg.shamdata%7Csham%7C0.3%7Cjar] 
> to generate realistic looking test data for both parameterized tests and user 
> acceptance testing. We log the seed that is used for each run so that if 
> there is an issue we can recreate exactly the same test data. I would also 
> like to use some of the commons-lang RandomStringUtils functionality but 
> notice that the implementation provides no way of setting the random number 
> generator to be used.
> {code}private static final Random RANDOM = new Random();{code}
> A way to configure this would be really useful. If there is an alternative 
> way to do this then that would be great. If you think it's a good idea and it 
> requires a patch I'm happy to supply one.
> Cheers,
> Gus.
>  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)