Skip to content

INTERNAL: Remove public ArcusClient constructor. #764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,53 @@ protected static ArcusClient getInstance(ConnectionFactory cf,
return new ArcusClient(cf, name, addrs);
}

/**
* Create an Arcus client for the given memcached server addresses.
* Recommend only invoked with arcus server without zk.
* @param addrs socket addresses for the memcached servers
* @param cfb connection factory builder to configure connections for this client
* @return Arcus client instance
* @throws IOException
*/
public static ArcusClient createArcusClient(List<InetSocketAddress> addrs,
ConnectionFactoryBuilder cfb)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name, addrs, cfb 인자를 가지는 API도 제공해야 하지 않는 지 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래와 같이 의견이 취합되었습니다.

#764 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliviarla
위 내용 검토해 주시죠.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zookeeper 주소를 입력받는 createArcusClient 메서드에도 name을 입력받지 않고 있으며 name 필드 자체가 내부적으로 로깅 용도로 사용하는 값이므로, 제 생각에는 name을 입력받는 메서드를 별도로 추가하지 않아도 될 것 같습니다.

throws IOException {
return new ArcusClient(cfb.build(), addrs);
}

/**
* Create an Arcus client pool for the given memcached server addresses.
* Recommend only invoked with arcus server without zk.
* @param addrs socket addresses for the memcached servers
* @param cfb connection factory builder to configure connections for this client
* @param poolSize pool size
* @return Arcus client pool instance
* @throws IOException
*/
public static ArcusClientPool createArcusClientPool(List<InetSocketAddress> addrs,
ConnectionFactoryBuilder cfb, int poolSize)
throws IOException {
ArcusClient[] clients = new ArcusClient[poolSize];
int poolId = CacheManager.POOL_ID.getAndIncrement();
for (int i = 0; i < poolSize; i++) {
String clientName = "ArcusClient" + "-" + poolId +
"(" + (i + 1) + "-" + poolSize + ")";
clients[i] = new ArcusClient(cfb.build(), clientName, addrs);
}
return new ArcusClientPool(poolSize, clients);
}

/**
* Create an Arcus client for the given memcached server addresses.
*
* @param cf connection factory to configure connections for this client
* @param name client name
* @param addrs socket addresses for the memcached servers
* @throws IOException if connections cannot be established
* @deprecated Use {@link #createArcusClient(java.util.List, ConnectionFactoryBuilder)} instead.
*/
@SuppressWarnings("this-escape")
@Deprecated
public ArcusClient(ConnectionFactory cf, String name, List<InetSocketAddress> addrs)
throws IOException {
super(cf, name, addrs);
Expand All @@ -369,7 +407,9 @@ public ArcusClient(ConnectionFactory cf, String name, List<InetSocketAddress> ad
* @param cf connection factory to configure connections for this client
* @param addrs socket addresses for the memcached servers
* @throws IOException if connections cannot be established
* @deprecated Use {@link #createArcusClient(java.util.List, ConnectionFactoryBuilder)} instead.
*/
@Deprecated
public ArcusClient(ConnectionFactory cf, List<InetSocketAddress> addrs)
throws IOException {
this(cf, DEFAULT_ARCUS_CLIENT_NAME + "-" + CLIENT_ID.getAndIncrement(), addrs);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/spy/memcached/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class CacheManager extends SpyThread implements Watcher,
private static final int ZK_SESSION_TIMEOUT = 15000;

private static final long ZK_CONNECT_TIMEOUT = ZK_SESSION_TIMEOUT;
private static final AtomicInteger POOL_ID = new AtomicInteger(1);
static final AtomicInteger POOL_ID = new AtomicInteger(1);

private final String zkConnectString;

Expand Down
15 changes: 4 additions & 11 deletions src/test/java/net/spy/memcached/ArcusTimeoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ protected void setUp() throws Exception {
}

private void initClient() throws IOException {
mc = new ArcusClient(new DefaultConnectionFactory() {
@Override
public long getOperationTimeout() {
return 1;
}

@Override
public FailureMode getFailureMode() {
return FailureMode.Retry;
}
}, AddrUtil.getAddresses("0.0.0.0:23456"));
mc = ArcusClient.createArcusClient(AddrUtil.getAddresses("0.0.0.0:23456"),
new ConnectionFactoryBuilder()
.setOpTimeout(1)
.setFailureMode(FailureMode.Retry));
}

@AfterEach
Expand Down
9 changes: 6 additions & 3 deletions src/test/java/net/spy/memcached/ClientBaseCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,19 @@ protected void initClient(ConnectionFactory cf) throws Exception {
if (USE_ZK) {
openFromZK(new CFB(cf));
} else {
openDirect(cf);
openDirect(new ConnectionFactoryBuilder()
.setOpTimeout(cf.getOperationTimeout())
.setFailureMode(cf.getFailureMode())
.setInitialObservers(cf.getInitialObservers()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new CFB(cf) 호출하는 것과 어떤 차이가 있나요?

Copy link
Collaborator Author

@brido4125 brido4125 Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new CFB(cf)의 경우 내부적으로
getInitialObservers 메서드를 오버라이드해서
비어있는 리스트를 리턴합니다.

그래서 openDirect에서 new CFB(cf)를 호출할 경우 빈 리스트가 테스트 로직내에서 사용되어
ObesrverTest의 testInitialObservers 테스트 케이스에서 에러가 발생합니다.

}
}

protected void openFromZK(ConnectionFactoryBuilder cfb) {
client = ArcusClient.createArcusClient(ZK_ADDRESS, SERVICE_CODE, cfb);
}

protected void openDirect(ConnectionFactory cf) throws Exception {
client = new ArcusClient(cf, AddrUtil.getAddresses(ARCUS_HOST));
protected void openDirect(ConnectionFactoryBuilder cfb) throws Exception {
client = ArcusClient.createArcusClient(AddrUtil.getAddresses(ARCUS_HOST), cfb);
}

@BeforeEach
Expand Down
21 changes: 1 addition & 20 deletions src/test/manual/net/spy/memcached/ArcusClientCreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assumptions.assumeFalse;

Expand All @@ -37,20 +36,9 @@ protected void release() {
addrs.clear();
}

@Test
void testCreateClientWithCustomName() throws IOException {
ArcusClient arcusClient = new ArcusClient(new DefaultConnectionFactory(), clientName, addrs);

Collection<MemcachedNode> nodes = arcusClient.getAllNodes();
MemcachedNode node = nodes.iterator().next();

assertEquals(nodes.size(), 1);
assertEquals(node.getNodeName(), clientName + " " + hostName);
}

@Test
void testCreateClientWithDefaultName() throws IOException {
ArcusClient arcusClient = new ArcusClient(new DefaultConnectionFactory(), addrs);
ArcusClient arcusClient = ArcusClient.createArcusClient(addrs, new ConnectionFactoryBuilder());

Collection<MemcachedNode> nodes = arcusClient.getAllNodes();
assertEquals(nodes.size(), 1);
Expand All @@ -60,11 +48,4 @@ void testCreateClientWithDefaultName() throws IOException {
Matcher matcher = compile.matcher(node.getNodeName());
assertTrue(matcher.matches());
}

@Test
void testCreateClientNullName() throws IOException {
assertThrows(NullPointerException.class, () -> {
new ArcusClient(new DefaultConnectionFactory(), null, addrs);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void connectionLost(SocketAddress sa) {
};
cfb.setInitialObservers(Collections.singleton(obs));

mc = new ArcusClient(cfb.build(), AddrUtil.getAddresses(ARCUS_HOST));
mc = ArcusClient.createArcusClient(AddrUtil.getAddresses(ARCUS_HOST), cfb);
latch.await();
}

Expand Down