zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anmolnar <...@git.apache.org>
Subject [GitHub] zookeeper pull request #474: ZOOKEEPER-2977: Concurrency for addAuth corrupt...
Date Wed, 13 Jun 2018 18:04:09 GMT
Github user anmolnar commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/474#discussion_r195182437
  
    --- Diff: src/java/test/org/apache/zookeeper/server/ServerCnxnTest.java ---
    @@ -0,0 +1,130 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.zookeeper.server;
    +
    +import java.io.IOException;
    +import java.net.InetAddress;
    +import java.net.InetSocketAddress;
    +import java.nio.ByteBuffer;
    +import java.util.List;
    +
    +import org.apache.jute.Record;
    +import org.apache.zookeeper.WatchedEvent;
    +import org.apache.zookeeper.ZKTestCase;
    +import org.apache.zookeeper.data.Id;
    +import org.apache.zookeeper.proto.ReplyHeader;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +public class ServerCnxnTest extends ZKTestCase {
    +
    +    /**
    +     * Test getting a copy of authinfo to avoid parallel modification impact
    +     */
    +    @Test
    +    public void testServerCnxnGetAuthInfoWithCopy() throws Exception {
    +        MockServerCnxn serverCnxn = new MockServerCnxn();
    +        List<Id> authInfo = serverCnxn.getAuthInfo();
    +        Id id = new Id("testscheme", "test");
    +        serverCnxn.addAuthInfo(id);
    +        Assert.assertFalse(authInfo.contains(id));
    +        Assert.assertTrue(serverCnxn.getAuthInfo().contains(id));
    +    }
    +    
    +    /**
    +     * Mock extension of ServerCnxn dummy to test for
    +     * AuthInfo behavior (ZOOKEEPER-2977).
    +     */
    +    private static class MockServerCnxn extends ServerCnxn {
    --- End diff --
    
    Up to you. 
    
    But, it's generally better to keep the scope of this patch for changes strictly related
to the Jira and create separate one for other refactorings.
    
    I'm happy to commit both, but you need to do the paperwork.


---

Mime
View raw message