curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From madrob <...@git.apache.org>
Subject [GitHub] curator pull request: CURATOR-79 - Modified the 'withProtection' h...
Date Mon, 11 Aug 2014 13:59:02 GMT
Github user madrob commented on a diff in the pull request:

    https://github.com/apache/curator/pull/35#discussion_r16053962
  
    --- Diff: curator-recipes/src/test/java/org/apache/curator/framework/recipes/locks/TestInterProcessMutex.java
---
    @@ -107,4 +113,70 @@ public Void call() throws Exception
                 client.close();
             }
         }
    +    
    +    /**
    +     * See CURATOR-79. If the mutex is interrupted while attempting to acquire a lock
it is
    +     * possible for the zNode to be created in ZooKeeper, but for Curator to think that
it
    +     * hasn't been. This causes the next call to acquire() to fail because the an orphaned
    +     * zNode has been left behind from the previous call.
    +     */
    +    @Test
    +    public void testInterruptedDuringAcquire() throws Exception
    +    {
    +        Timing timing = new Timing();
    +        final CuratorFramework        client = CuratorFrameworkFactory.newClient(server.getConnectString(),
new RetryOneTime(1));
    +        client.start();
    +        final InterProcessMutex       lock = new InterProcessMutex(client, LOCK_PATH);
    +        
    +        final AtomicBoolean interruptOnError = new AtomicBoolean(true);
    +        
    +        ((CuratorFrameworkImpl)client).debugUnhandledErrorListener = new UnhandledErrorListener()
    +        {
    +            
    +            @Override
    +            public void unhandledError(String message, Throwable e)
    +            {
    +                if(interruptOnError.compareAndSet(true, false))
    +                {
    +                    Thread.currentThread().interrupt();
    +                }
    +            }
    +        };
    +        
    +        //The lock path needs to exist for the deadlock to occur.
    +        try {
    +            client.create().creatingParentsIfNeeded().forPath(LOCK_PATH);
    +        } catch(NodeExistsException e) {            
    +        }
    +        
    +        try
    +        {
    +            //Interrupt the current thread. This will cause ensurePath() to fail.
    +            //We need to reinterrupt in the debugUnhandledErrorListener above.
    +            Thread.currentThread().interrupt();
    +            lock.acquire();
    +            Assert.fail();
    +        }
    +        catch(InterruptedException e)
    +        {
    +            //Expected lock to have failed.
    +            Assert.assertTrue(!lock.isOwnedByCurrentThread());
    --- End diff --
    
    nit: assertFalse


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message