/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.client.lineage;

import alluxio.Configuration;
import alluxio.PropertyKey;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * Tests {@link LineageContext}.
 */
public final class LineageContextTest {

  /**
   * Tests the concurrency of the {@link LineageContext}.
   */
  @Test
  public void concurrency() throws Exception {
    final List<LineageMasterClient> clients = new ArrayList<>();

    // acquire all the clients
    for (int i = 0; i < Configuration.getInt(PropertyKey.USER_LINEAGE_MASTER_CLIENT_THREADS); i++) {
      clients.add(LineageContext.INSTANCE.acquireMasterClient());
    }

    (new Thread(new AcquireClient())).start();

    // wait for thread to run
    Thread.sleep(5L);

    // release all the clients
    for (LineageMasterClient client : clients) {
      LineageContext.INSTANCE.releaseMasterClient(client);
    }
  }

  class AcquireClient implements Runnable {
    @Override
    public void run() {
      LineageMasterClient client = LineageContext.INSTANCE.acquireMasterClient();
      LineageContext.INSTANCE.releaseMasterClient(client);
    }
  }
}

@@ -551,133 +551,186 @@
 ort 
-alluxio.Configuration;%0Aimport alluxio.PropertyKey;%0A%0Aimport org.junit.Test;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List
+java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0Aimport alluxio.Configuration;%0Aimport alluxio.PropertyKey
 ;%0A%0A/
@@ -1573,16 +1573,51 @@
 client =
+ null;%0A      try %7B%0A        client =
  Lineage
@@ -1656,16 +1656,163 @@
 ient();%0A
+      %7D catch (IOException e) %7B%0A        Assert.fail(%22Failed to acquire a lineage master client due to interruption occured.%22);%0A      %7D finally %7B%0A  
       Li
@@ -1854,28 +1854,36 @@
 Client(client);%0A
+      %7D%0A
     %7D%0A  %7D%0A%7D%0A

Modify relevant classes