[ 
https://issues.apache.org/jira/browse/GEODE-5644?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16988071#comment-16988071
 ] 

ASF subversion and git services commented on GEODE-5644:
--------------------------------------------------------

Commit bd1e1491618bef2250ec1e382d3a03c74aa345da in geode's branch 
refs/heads/develop from Kirk Lund
[ https://gitbox.apache.org/repos/asf?p=geode.git;h=bd1e149 ]

GEODE-5644: Add new DistributedReference JUnit Rule

JUnit Rule that provides a static reference in every distributed test
VMs including the main JUnit controller VM. If the referenced value is
is an AutoCloseable or Closeable then it will be auto-closed in every
VM during tear down.

If the referenced value is not an AutoCloseable or Closeable, the
DistributedReference will use reflection to invoke any method named
close or disconnect regardless of what interfaces are implemented.

If the referenced value is null in any VM then it will be ignored in
that VM during tear down.

To disable auto-close, simply specify autoClose(false).

See the javadocs on DistributedReference for more info.


> New DistributedReference JUnit rule for DistributedTests
> --------------------------------------------------------
>
>                 Key: GEODE-5644
>                 URL: https://issues.apache.org/jira/browse/GEODE-5644
>             Project: Geode
>          Issue Type: Wish
>          Components: tests
>            Reporter: Kirk Lund
>            Assignee: Kirk Lund
>            Priority: Major
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> I'd like to add a new DistributedReference JUnit rule for DistributedTests 
> which would be used similar to an AtomicReference but with a reference that 
> is useable within every DUnit VM.
> The idea is that this would allow us to define something like:
> {noformat}
> @Rule
> public DistributedReference<Cache> cacheReference = new 
> DistributedReference<>();
> @Before
> public void setUp() {
>   getVM(0).invoke(() -> cacheReference.set(new CacheFactory().create());
> }
> @After
> public void tearDown() {
>   getVM(0).invoke(() -> cacheReference.get().close());
> }
> {noformat}
> Each DUnit VM would have its own instance of Cache (or other type) available 
> to set and get with this rule.
> This enables us to the Geode APIs directly within a test without depending on 
> more complex custom rules like CacheRule or ClusterStarterRule. This would 
> make tests that use it more directly dependent on the User APIs and force us 
> to become more aware of of the shortcomings of that API including its 
> defaults. If the Geode User APIs for creating and closing Cache is so 
> difficult or verbose to use or has the wrong defaults, then this will 
> encourage us to fix the Geode User API instead of hiding it behind complex 
> custom rules that act as an API Adapter layer.
> We could also consider adding support for java.io.Closeable since resources 
> such as Cache implement Closeable. This would then obviate the need to 
> implement @After in most cases.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to