Skip to content

Commit

Permalink
Fix concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
terence-yoo committed Mar 10, 2018
1 parent 24ed4a0 commit 96679f0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,8 @@ public OptionSet getOptionSet() {
public boolean isForceProceed() {
return optionSet.has(OPTION_FORCE_PROCEED);
}

public String hashStr() {
return Integer.toHexString(optionSet.hashCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class HBaseClient {
private HBaseClient() {
}

private static String createJaasConfigFile(Args args, String fileName) throws FileNotFoundException, UnsupportedEncodingException {
private static String createJaasConfigFile(Args args) throws FileNotFoundException, UnsupportedEncodingException {
StringBuilder sb = new StringBuilder();
sb.append("Client {\n");
sb.append("com.sun.security.auth.module.Krb5LoginModule required\n");
Expand All @@ -60,7 +60,7 @@ private static String createJaasConfigFile(Args args, String fileName) throws Fi
}
sb.append(";};");

String authConfFileName = "/tmp/" + fileName;
String authConfFileName = "/tmp/" + "hbase-client-" + args.hashStr() + ".jaas";
try (PrintWriter writer = new PrintWriter(authConfFileName, Constant.CHARSET.name())) {
writer.print(sb);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ private static synchronized void login(Args args, Configuration conf) throws Exc
System.setProperty("sun.security.spnego.debug", "true");
}

System.setProperty("java.security.auth.login.config", createJaasConfigFile(args, "hbase-client.jaas"));
System.setProperty("java.security.auth.login.config", createJaasConfigFile(args));
System.setProperty("java.security.krb5.conf", kerberosConfigFile(args));

Config krbConfig = Config.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.kakao.hbase;

import com.kakao.hbase.common.Args;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
Expand Down Expand Up @@ -85,4 +86,39 @@ public void testShortAndLongName() throws IOException {
args = new TestBase.TestArgs(argsParam);
assertEquals("k1", args.valueOf(Args.OPTION_KEY_TAB, Args.OPTION_KEY_TAB_SHORT));
}

@Test
public void testHashStr() throws IOException {
String[] argsParam;
Args args;

argsParam = new String[]{"zookeeper", "--conf=a=a1"};
args = new TestBase.TestArgs(argsParam);
String hashStr1 = args.hashStr();

argsParam = new String[]{"zookeeper", "--conf=a=a1"};
args = new TestBase.TestArgs(argsParam);
String hashStr2 = args.hashStr();
Assert.assertEquals(hashStr1, hashStr2);

argsParam = new String[]{"zookeeper", "-ca=a1"};
args = new TestBase.TestArgs(argsParam);
String hashStr3 = args.hashStr();
Assert.assertNotEquals(hashStr1, hashStr3);

argsParam = new String[]{"zookeeper", "--principal=p1"};
args = new TestBase.TestArgs(argsParam);
String hashStr4 = args.hashStr();
Assert.assertNotEquals(hashStr1, hashStr4);

argsParam = new String[]{"zookeeper2", "--principal=p1"};
args = new TestBase.TestArgs(argsParam);
String hashStr5 = args.hashStr();
Assert.assertNotEquals(hashStr4, hashStr5);

argsParam = new String[]{"zookeeper2", "--principal=p1", "--principal=p2"};
args = new TestBase.TestArgs(argsParam);
String hashStr6 = args.hashStr();
Assert.assertNotEquals(hashStr5, hashStr6);
}
}

0 comments on commit 96679f0

Please sign in to comment.