create();
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/OperationState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.ops;
18 |
19 | /**
20 | * State of this operation.
21 | */
22 | public enum OperationState {
23 | /**
24 | * State indicating this operation is waiting to be written to the server.
25 | */
26 | WRITE_QUEUED,
27 | /**
28 | * State indicating this operation is writing data to the server.
29 | */
30 | WRITING,
31 | /**
32 | * State indicating this operation is reading data from the server.
33 | */
34 | READING,
35 | /**
36 | * State indicating this operation is complete.
37 | */
38 | COMPLETE,
39 | /* ENABLE_REPLICATION if */
40 | /**
41 | * State indicating this operation received SWITCHOVER | REPL_SLAVE
42 | * and the node handling this operation need to switchover in the locator.
43 | */
44 | NEED_SWITCHOVER,
45 | /* ENABLE_REPLICATION end */
46 |
47 | /* ENABLE_MIGRATION if */
48 | /**
49 | * State indicating this operation will be redirected by migration
50 | */
51 | REDIRECT
52 | /* ENABLE_MIGRATION end */
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/OperationStatus.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | import java.util.Objects;
4 |
5 | /**
6 | * Status indicator.
7 | */
8 | public class OperationStatus {
9 |
10 | private final boolean isSuccess;
11 | private final String message;
12 | private final StatusCode statusCode;
13 |
14 | public OperationStatus(boolean success, String msg) {
15 | this(success, msg, null);
16 | }
17 |
18 | public OperationStatus(boolean success, String msg, StatusCode code) {
19 | isSuccess = success;
20 | message = msg;
21 | statusCode = code;
22 | }
23 |
24 | /**
25 | * Does this status indicate success?
26 | */
27 | public boolean isSuccess() {
28 | return isSuccess;
29 | }
30 |
31 | /**
32 | * Get the message included as part of this status.
33 | */
34 | public String getMessage() {
35 | return message;
36 | }
37 |
38 | /**
39 | * Get the status code associated with the operation status.
40 | */
41 | public StatusCode getStatusCode() {
42 | return statusCode;
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return "{OperationStatus success=" + isSuccess + ": " + message + "}";
48 | }
49 |
50 | @Override
51 | public boolean equals(Object o) {
52 | if (this == o) {
53 | return true;
54 | }
55 | if (o == null || getClass() != o.getClass()) {
56 | return false;
57 | }
58 |
59 | OperationStatus that = (OperationStatus) o;
60 | return isSuccess == that.isSuccess &&
61 | Objects.equals(message, that.message) &&
62 | Objects.equals(statusCode, that.statusCode);
63 | }
64 |
65 | @Override
66 | public int hashCode() {
67 | return Objects.hash(isSuccess, message, statusCode);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/PipedOperationCallback.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | public interface PipedOperationCallback extends OperationCallback {
4 | void gotStatus(Integer index, OperationStatus status);
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/SASLAuthOperation.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | /**
4 | * Operation for beginning a SASL auth cycle.
5 | */
6 | public interface SASLAuthOperation extends Operation {
7 | // nothing
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/SASLMechsOperation.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | /**
4 | * Operation for listing supported SASL mechanisms.
5 | */
6 | public interface SASLMechsOperation extends Operation {
7 | // Nothing.
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/SASLStepOperation.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | /**
4 | * Operation for proceeding in a SASL auth negotiation.
5 | */
6 | public interface SASLStepOperation extends Operation {
7 | // nothing
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/SetAttrOperation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.ops;
18 |
19 | import net.spy.memcached.collection.Attributes;
20 |
21 | /**
22 | * SetAttr operation.
23 | */
24 | public interface SetAttrOperation extends KeyedOperation {
25 |
26 | Attributes getAttributes();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/StatsOperation.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 |
4 | /**
5 | * Stats fetching operation.
6 | */
7 | public interface StatsOperation extends Operation {
8 |
9 | /**
10 | * Callback for stats operation.
11 | */
12 | interface Callback extends OperationCallback {
13 | /**
14 | * Invoked once for every stat returned from the server.
15 | *
16 | * @param name the name of the stat
17 | * @param val the stat value.
18 | */
19 | void gotStat(String name, String val);
20 | }
21 | // nothing
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/StoreOperation.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | /**
4 | * Operation that represents object storage.
5 | */
6 | public interface StoreOperation extends KeyedOperation {
7 |
8 | /**
9 | * Get the store type used by this operation.
10 | */
11 | StoreType getStoreType();
12 |
13 | /**
14 | * Get the flags to be set.
15 | */
16 | int getFlags();
17 |
18 | /**
19 | * Get the expiration value to be set.
20 | */
21 | int getExpiration();
22 |
23 | /**
24 | * Get the bytes to be set during this operation.
25 | *
26 | *
27 | * Note, this returns an exact reference to the bytes and the data
28 | * must not be modified.
29 | *
30 | */
31 | byte[] getData();
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/StoreType.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | /**
4 | * The type of storage operation to perform.
5 | */
6 | public enum StoreType {
7 | /**
8 | * Unconditionally store a value in the cache.
9 | */
10 | set,
11 | /**
12 | * Store a value in the cache iff there is not already something stored
13 | * for the given key.
14 | */
15 | add,
16 | /**
17 | * Store a value in the cache iff there is already something stored for
18 | * the given key.
19 | */
20 | replace
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/VersionOperation.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.ops;
2 |
3 | /**
4 | * Version operation.
5 | */
6 | public interface VersionOperation extends Operation {
7 | // nothing
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/ops/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Fundamental protocol operation interfaces
8 |
9 |
10 |
11 | Fundamental protocol operation interfaces
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/overview.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Welcome to spymemcached
8 |
9 |
10 |
11 |
12 | Welcome to spymemcached.
13 |
14 |
15 | Get a {@link net.spy.memcached.MemcachedClient} object and start setting and
16 | getting stuff in memcached.
17 |
18 |
19 |
20 | You may also find the
21 | online examples
22 | helpful.
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Memcached client and transformation utils
8 |
9 |
10 |
11 | Memcached client and transformation utils
12 |
13 |
14 | Usage should be pretty straightforward. Get a {@link
15 | net.spy.memcached.MemcachedClient} object and start setting and
16 | getting stuff in memcached.
17 |
18 |
19 | All operations are asynchronous internally, but most at least provide
20 | synchronous convenience interfaces. Some only provide synchronous
21 | interfaces (getVersion, getStats) and some only provide asynchronous
22 | interfaces (delete, flush). That'll probably all get cleared up if it
23 | bothers anyone.
24 |
25 |
26 | You may also find the
27 | online examples
28 | helpful.
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/GetCallbackWrapper.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package net.spy.memcached.protocol;
5 |
6 | import net.spy.memcached.ops.GetOperation;
7 | import net.spy.memcached.ops.OperationStatus;
8 | import net.spy.memcached.ops.StatusCode;
9 |
10 | /**
11 | * Wrapper callback for use in optimized gets.
12 | */
13 | public class GetCallbackWrapper implements GetOperation.Callback {
14 |
15 | private static final OperationStatus END =
16 | new OperationStatus(true, "END", StatusCode.SUCCESS);
17 |
18 | private boolean completed = false;
19 | private int remainingKeys = 0;
20 | private GetOperation.Callback cb = null;
21 |
22 | public GetCallbackWrapper(int k, GetOperation.Callback c) {
23 | super();
24 | remainingKeys = k;
25 | cb = c;
26 | }
27 |
28 | public void gotData(String key, int flags, byte[] data) {
29 | assert !completed : "Got data for a completed wrapped op";
30 | cb.gotData(key, flags, data);
31 | if (--remainingKeys == 0) {
32 | // Fake a status line
33 | receivedStatus(END);
34 | }
35 | }
36 |
37 | public void receivedStatus(OperationStatus status) {
38 | if (!completed) {
39 | cb.receivedStatus(status);
40 | }
41 | }
42 |
43 | public void complete() {
44 | assert !completed;
45 | cb.complete();
46 | completed = true;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/ascii/GetOperationImpl.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006 Dustin Sallings
2 |
3 | package net.spy.memcached.protocol.ascii;
4 |
5 | import java.util.Collection;
6 | import java.util.Collections;
7 | import java.util.HashSet;
8 |
9 | import net.spy.memcached.ops.APIType;
10 | import net.spy.memcached.ops.GetOperation;
11 |
12 | /**
13 | * Operation for retrieving data.
14 | */
15 | class GetOperationImpl extends BaseGetOpImpl implements GetOperation {
16 |
17 | private static final String CMD = "get";
18 | private static final String CMD_MGET = "mget";
19 |
20 | public GetOperationImpl(String key, GetOperation.Callback c) {
21 | super(CMD, c, Collections.singleton(key));
22 | setAPIType(APIType.GET);
23 | }
24 |
25 | public GetOperationImpl(Collection keys, GetOperation.Callback cb, boolean isMGet) {
26 | super(isMGet ? CMD_MGET : CMD, cb, new HashSet<>(keys));
27 | setAPIType(APIType.GET);
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/ascii/GetsOperationImpl.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.ascii;
2 |
3 | import java.util.Collection;
4 | import java.util.Collections;
5 | import java.util.HashSet;
6 |
7 | import net.spy.memcached.ops.APIType;
8 | import net.spy.memcached.ops.GetsOperation;
9 |
10 | /**
11 | * Implementation of the gets operation.
12 | */
13 | class GetsOperationImpl extends BaseGetOpImpl implements GetsOperation {
14 |
15 | private static final String CMD = "gets";
16 | private static final String CMD_MGETS = "mgets";
17 |
18 | public GetsOperationImpl(String key, GetsOperation.Callback cb) {
19 | super(CMD, cb, Collections.singleton(key));
20 | setAPIType(APIType.GETS);
21 | }
22 |
23 | public GetsOperationImpl(Collection keys, GetsOperation.Callback cb, boolean isMGet) {
24 | super(isMGet ? CMD_MGETS : CMD, cb, new HashSet<>(keys));
25 | setAPIType(APIType.GETS);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/ascii/OperationReadType.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.ascii;
2 |
3 | /**
4 | * Data read types.
5 | */
6 | enum OperationReadType {
7 | /**
8 | * Read type indicating an operation currently wants to read lines.
9 | */
10 | LINE,
11 | /**
12 | * Read type indicating an operation currently wants to read raw data.
13 | */
14 | DATA
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/ascii/OptimizedGetImpl.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.ascii;
2 |
3 | import java.util.HashSet;
4 |
5 | import net.spy.memcached.ops.GetOperation;
6 | import net.spy.memcached.protocol.ProxyCallback;
7 |
8 | /**
9 | * Optimized Get operation for folding a bunch of gets together.
10 | */
11 | final class OptimizedGetImpl extends GetOperationImpl {
12 |
13 | private final ProxyCallback pcb;
14 |
15 | /**
16 | * Construct an optimized get starting with the given get operation.
17 | */
18 | public OptimizedGetImpl(GetOperation firstGet, boolean isMGet) {
19 | super(new HashSet<>(), new ProxyCallback(), isMGet);
20 | pcb = (ProxyCallback) getCallback();
21 | addOperation(firstGet);
22 | }
23 |
24 | /**
25 | * Add a new GetOperation to get.
26 | */
27 | public void addOperation(GetOperation o) {
28 | getKeys().addAll(o.getKeys());
29 | pcb.addCallbacks(o);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/ascii/StoreOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | // Copyright (c) 2006 Dustin Sallings
19 |
20 | package net.spy.memcached.protocol.ascii;
21 |
22 | import net.spy.memcached.ops.APIType;
23 | import net.spy.memcached.ops.OperationCallback;
24 | import net.spy.memcached.ops.StoreOperation;
25 | import net.spy.memcached.ops.StoreType;
26 |
27 | /**
28 | * Operation to store data in a memcached server.
29 | */
30 | final class StoreOperationImpl extends BaseStoreOperationImpl
31 | implements StoreOperation {
32 |
33 | private final StoreType storeType;
34 |
35 | public StoreOperationImpl(StoreType t, String k, int f, int e,
36 | byte[] d, OperationCallback cb) {
37 | super(t.name(), k, f, e, d, cb);
38 | storeType = t;
39 | if (t == StoreType.add) {
40 | setAPIType(APIType.ADD);
41 | } else if (t == StoreType.set) {
42 | setAPIType(APIType.SET);
43 | } else if (t == StoreType.replace) {
44 | setAPIType(APIType.REPLACE);
45 | }
46 | }
47 |
48 | public StoreType getStoreType() {
49 | return storeType;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/ascii/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Low-level operations for the memcached ascii protocol
8 |
9 |
10 |
11 | Low-level operations for the memcached ascii protocol
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/FlushOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package net.spy.memcached.protocol.binary;
19 |
20 | import net.spy.memcached.ops.FlushOperation;
21 | import net.spy.memcached.ops.OperationCallback;
22 |
23 | class FlushOperationImpl extends OperationImpl implements FlushOperation {
24 |
25 | private static final int CMD = 8;
26 | private final int delay;
27 |
28 | public FlushOperationImpl(OperationCallback cb) {
29 | this(0, cb);
30 | }
31 |
32 | public FlushOperationImpl(int d, OperationCallback cb) {
33 | super(CMD, generateOpaque(), cb);
34 | delay = d;
35 | }
36 |
37 | @Override
38 | public void initialize() {
39 | prepareBuffer("", 0, EMPTY_BYTES, delay);
40 | }
41 |
42 | @Override
43 | public boolean isIdempotentOperation() {
44 | return false;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/NoopOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package net.spy.memcached.protocol.binary;
19 |
20 | import net.spy.memcached.ops.NoopOperation;
21 | import net.spy.memcached.ops.OperationCallback;
22 |
23 | /**
24 | * Implementation of a noop operation.
25 | */
26 | class NoopOperationImpl extends OperationImpl implements NoopOperation {
27 |
28 | static final int CMD = 10;
29 |
30 | public NoopOperationImpl(OperationCallback cb) {
31 | super(CMD, generateOpaque(), cb);
32 | }
33 |
34 | @Override
35 | public void initialize() {
36 | prepareBuffer("", 0, EMPTY_BYTES);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/OptimizedGetImpl.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.binary;
2 |
3 | import java.util.Collections;
4 |
5 | import net.spy.memcached.ops.GetOperation;
6 | import net.spy.memcached.protocol.ProxyCallback;
7 |
8 | /**
9 | * Optimized Get operation for folding a bunch of gets together.
10 | */
11 | final class OptimizedGetImpl extends MultiGetOperationImpl {
12 |
13 | private final ProxyCallback pcb;
14 |
15 | /**
16 | * Construct an optimized get starting with the given get operation.
17 | */
18 | public OptimizedGetImpl(GetOperation firstGet) {
19 | super(Collections.emptySet(), new ProxyCallback());
20 | pcb = (ProxyCallback) getCallback();
21 | addOperation(firstGet);
22 | }
23 |
24 | /**
25 | * Add a new GetOperation to get.
26 | */
27 | public void addOperation(GetOperation o) {
28 | pcb.addCallbacks(o);
29 | for (String k : o.getKeys()) {
30 | addKey(k);
31 | }
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/SASLAuthOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package net.spy.memcached.protocol.binary;
19 |
20 | import javax.security.sasl.SaslClient;
21 | import javax.security.sasl.SaslException;
22 |
23 | import net.spy.memcached.ops.OperationCallback;
24 | import net.spy.memcached.ops.SASLAuthOperation;
25 |
26 | public class SASLAuthOperationImpl extends SASLBaseOperationImpl
27 | implements SASLAuthOperation {
28 |
29 | private final static int CMD = 0x21;
30 |
31 | public SASLAuthOperationImpl(SaslClient sc, OperationCallback cb) {
32 | super(CMD, sc, EMPTY_BYTES, cb);
33 | }
34 |
35 | @Override
36 | protected byte[] buildResponse(SaslClient sc) throws SaslException {
37 | return sc.hasInitialResponse() ?
38 | sc.evaluateChallenge(challenge)
39 | : EMPTY_BYTES;
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/SASLMechsOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package net.spy.memcached.protocol.binary;
19 |
20 | import net.spy.memcached.ops.OperationCallback;
21 | import net.spy.memcached.ops.OperationStatus;
22 | import net.spy.memcached.ops.SASLMechsOperation;
23 | import net.spy.memcached.ops.StatusCode;
24 |
25 | class SASLMechsOperationImpl extends OperationImpl implements
26 | SASLMechsOperation {
27 |
28 | private static final int CMD = 0x20;
29 |
30 | public SASLMechsOperationImpl(OperationCallback cb) {
31 | super(CMD, generateOpaque(), cb);
32 | }
33 |
34 | @Override
35 | public void initialize() {
36 | prepareBuffer("", 0, EMPTY_BYTES);
37 | }
38 |
39 | @Override
40 | protected void decodePayload(byte[] pl) {
41 | getCallback().receivedStatus(
42 | new OperationStatus(true, new String(pl), StatusCode.SUCCESS));
43 | }
44 |
45 |
46 | @Override
47 | public boolean isIdempotentOperation() {
48 | return false;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/SASLStepOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package net.spy.memcached.protocol.binary;
19 |
20 | import javax.security.sasl.SaslClient;
21 | import javax.security.sasl.SaslException;
22 |
23 | import net.spy.memcached.ops.OperationCallback;
24 | import net.spy.memcached.ops.SASLStepOperation;
25 |
26 | public class SASLStepOperationImpl extends SASLBaseOperationImpl
27 | implements SASLStepOperation {
28 |
29 | private final static int CMD = 0x22;
30 |
31 | public SASLStepOperationImpl(SaslClient sc, byte[] challenge, OperationCallback cb) {
32 | super(CMD, sc, challenge, cb);
33 | }
34 |
35 | @Override
36 | protected byte[] buildResponse(SaslClient sc) throws SaslException {
37 | return sc.evaluateChallenge(challenge);
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/VersionOperationImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | * Copyright 2014-2022 JaM2in Co., Ltd.
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 | package net.spy.memcached.protocol.binary;
19 |
20 | import net.spy.memcached.ops.OperationCallback;
21 | import net.spy.memcached.ops.OperationStatus;
22 | import net.spy.memcached.ops.StatusCode;
23 | import net.spy.memcached.ops.VersionOperation;
24 |
25 | class VersionOperationImpl extends OperationImpl implements VersionOperation {
26 |
27 | private static final int CMD = 11;
28 |
29 | public VersionOperationImpl(OperationCallback cb) {
30 | super(CMD, generateOpaque(), cb);
31 | }
32 |
33 | @Override
34 | public void initialize() {
35 | prepareBuffer("", 0, EMPTY_BYTES);
36 | }
37 |
38 | @Override
39 | protected void decodePayload(byte[] pl) {
40 | getCallback().receivedStatus(
41 | new OperationStatus(true, new String(pl), StatusCode.SUCCESS));
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/binary/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Low-level operations for the memcached binary protocol
8 |
9 |
10 |
11 | Low-level operations for the memcached binary protocol
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/protocol/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Base classes for protocol abstractions.
8 |
9 |
10 |
11 | Base classes for protocol abstractions.
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/transcoders/InspectObjectSizeTranscoder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.transcoders;
18 |
19 | import net.spy.memcached.CachedData;
20 |
21 | public class InspectObjectSizeTranscoder extends SerializingTranscoder {
22 |
23 | public interface LoggingObjectSize {
24 | void histogram(int size);
25 | }
26 |
27 | private final LoggingObjectSize objSizeLogger;
28 |
29 | public InspectObjectSizeTranscoder(LoggingObjectSize objSizeLogger) {
30 | this.objSizeLogger = objSizeLogger;
31 | }
32 |
33 | @Override
34 | public CachedData encode(Object o) {
35 | CachedData encoded = super.encode(o);
36 |
37 | objSizeLogger.histogram(encoded.getData().length);
38 |
39 | return encoded;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/transcoders/IntegerTranscoder.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006 Dustin Sallings
2 |
3 | package net.spy.memcached.transcoders;
4 |
5 | import net.spy.memcached.CachedData;
6 | import net.spy.memcached.compat.SpyObject;
7 |
8 | /**
9 | * Transcoder that serializes and unserializes longs.
10 | */
11 | public final class IntegerTranscoder extends SpyObject
12 | implements Transcoder {
13 |
14 | private static final int flags = SerializingTranscoder.SPECIAL_INT;
15 |
16 | private final TranscoderUtils tu = new TranscoderUtils(true);
17 |
18 | public boolean asyncDecode(CachedData d) {
19 | return false;
20 | }
21 |
22 | public CachedData encode(java.lang.Integer l) {
23 | return new CachedData(flags, tu.encodeInt(l), getMaxSize());
24 | }
25 |
26 | public Integer decode(CachedData d) {
27 | if (flags == d.getFlags()) {
28 | return tu.decodeInt(d.getData());
29 | } else {
30 | return null;
31 | }
32 | }
33 |
34 | public int getMaxSize() {
35 | return CachedData.MAX_SIZE;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/transcoders/LongTranscoder.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006 Dustin Sallings
2 |
3 | package net.spy.memcached.transcoders;
4 |
5 | import net.spy.memcached.CachedData;
6 | import net.spy.memcached.compat.SpyObject;
7 |
8 | /**
9 | * Transcoder that serializes and unserializes longs.
10 | */
11 | public final class LongTranscoder extends SpyObject
12 | implements Transcoder {
13 |
14 | private static final int flags = SerializingTranscoder.SPECIAL_LONG;
15 |
16 | private final TranscoderUtils tu = new TranscoderUtils(true);
17 |
18 | public boolean asyncDecode(CachedData d) {
19 | return false;
20 | }
21 |
22 | public CachedData encode(java.lang.Long l) {
23 | return new CachedData(flags, tu.encodeLong(l), getMaxSize());
24 | }
25 |
26 | public Long decode(CachedData d) {
27 | if (flags == d.getFlags()) {
28 | return tu.decodeLong(d.getData());
29 | } else {
30 | getLogger().error("Unexpected flags for long: "
31 | + d.getFlags() + " wanted " + flags);
32 | return null;
33 | }
34 | }
35 |
36 | public int getMaxSize() {
37 | return CachedData.MAX_SIZE;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/transcoders/Transcoder.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2006 Dustin Sallings
2 |
3 | package net.spy.memcached.transcoders;
4 |
5 | import net.spy.memcached.CachedData;
6 |
7 | /**
8 | * Transcoder is an interface for classes that convert between byte arrays and
9 | * objects for storage in the cache.
10 | */
11 | public interface Transcoder {
12 |
13 | /**
14 | * Should the transcoder be run asynchronously.
15 | *
16 | * @return True if the CachedData should be decoded Asynchronously
17 | */
18 | boolean asyncDecode(CachedData d);
19 |
20 | /**
21 | * Encode the given object for storage.
22 | *
23 | * @param o the object
24 | * @return the CachedData representing what should be sent
25 | */
26 | CachedData encode(T o);
27 |
28 | /**
29 | * Decode the cached object into the object it represents.
30 | *
31 | * @param d the data
32 | * @return the return value
33 | */
34 | T decode(CachedData d);
35 |
36 | /**
37 | * Get the maximum size of objects handled by this transcoder.
38 | */
39 | int getMaxSize();
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/transcoders/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Transcoders convert data to and from data and flags
8 |
9 |
10 |
11 | Classes that deal with data encoding
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/util/KetamaNodeLocatorConfiguration.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.util;
2 |
3 | import net.spy.memcached.MemcachedNode;
4 |
5 | /**
6 | * Defines the set of all configuration dependencies
7 | * required for the KetamaNodeLocator algorithm to run
8 | */
9 | public interface KetamaNodeLocatorConfiguration {
10 |
11 | /**
12 | * Returns a uniquely identifying key, suitable for hashing by the
13 | * KetamaNodeLocator algorithm.
14 | *
15 | * @param node The MemcachedNode to use to form the unique identifier
16 | * @param repetition The repetition number for the particular node in
17 | * question (0 is the first repetition)
18 | * @return The key that represents the specific repetition of the node
19 | */
20 | String getKeyForNode(MemcachedNode node, int repetition);
21 |
22 | /**
23 | * Returns the number of discrete hashes that should be defined for each
24 | * node in the continuum.
25 | *
26 | * @return a value greater than 0
27 | */
28 | int getNodeRepetitions();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/net/spy/memcached/util/package.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 | Cache Utilities.
8 |
9 |
10 |
11 | Cache Utilities.
12 |
13 | Herein you'll find various things that make your life with cache
14 | a little better.
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/AsciiCancellationTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | /**
4 | * Test cancellation in ascii protocol.
5 | */
6 | class AsciiCancellationTest extends CancellationBaseCase {
7 | // uses defaults
8 | }
9 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/AsciiIPV6ClientTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.util.Collections;
4 |
5 | /**
6 | * Test the test protocol over IPv6.
7 | */
8 | class AsciiIPV6ClientTest extends AsciiClientTest {
9 |
10 | @Override
11 | protected void initClient(ConnectionFactory cf) throws Exception {
12 | client = new MemcachedClient(cf, AddrUtil.getAddresses(
13 | Collections.singletonList("::1:11211")));
14 | }
15 |
16 | @Override
17 | protected String getExpectedVersionSource() {
18 | return "/0:0:0:0:0:0:0:1:11211";
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/BinaryCancellationTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | /**
4 | * Test cancellation in the binary protocol.
5 | */
6 | class BinaryCancellationTest extends CancellationBaseCase {
7 |
8 | @Override
9 | protected void initClient() throws Exception {
10 | initClient(new BinaryConnectionFactory() {
11 | @Override
12 | public FailureMode getFailureMode() {
13 | return FailureMode.Retry;
14 | }
15 | });
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/BinaryIPV6ClientTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.util.Collections;
4 |
5 | /**
6 | * Binary IPv6 client test.
7 | */
8 | class BinaryIPV6ClientTest extends BinaryClientTest {
9 |
10 | @Override
11 | protected void initClient(ConnectionFactory cf) throws Exception {
12 | client = new MemcachedClient(cf, AddrUtil.getAddresses(
13 | Collections.singletonList("::1:11211")));
14 | }
15 |
16 | @Override
17 | protected String getExpectedVersionSource() {
18 | return "/0:0:0:0:0:0:0:1:11211";
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/CancelFailureModeTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.util.Collections;
4 | import java.util.concurrent.ExecutionException;
5 | import java.util.concurrent.Future;
6 |
7 | import org.junit.jupiter.api.AfterEach;
8 | import org.junit.jupiter.api.BeforeEach;
9 | import org.junit.jupiter.api.Test;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertTrue;
12 | import static org.junit.jupiter.api.Assertions.fail;
13 |
14 | class CancelFailureModeTest {
15 | private String serverList = "127.0.0.1:11311";
16 | private MemcachedClient client = null;
17 |
18 | @BeforeEach
19 | protected void setUp() throws Exception {
20 | client = new MemcachedClient(new DefaultConnectionFactory() {
21 | @Override
22 | public FailureMode getFailureMode() {
23 | return FailureMode.Cancel;
24 | }
25 | }, AddrUtil.getAddresses(Collections.singletonList(serverList)));
26 | }
27 |
28 | @AfterEach
29 | protected void tearDown() throws Exception {
30 | if (client != null) {
31 | client.shutdown();
32 | }
33 | }
34 |
35 | @Test
36 | void testQueueingToDownServer() throws Exception {
37 | Future f = client.add("someKey", 0, "some object");
38 | try {
39 | boolean b = f.get();
40 | fail("Should've thrown an exception, returned " + b);
41 | } catch (ExecutionException e) {
42 | // probably OK
43 | }
44 | assertTrue(f.isCancelled());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/ConnectionFactoryTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
6 |
7 | /**
8 | * Test connection factory variations.
9 | */
10 | class ConnectionFactoryTest {
11 |
12 | // These tests are a little lame. They don't verify anything other than
13 | // that the code executes without failure.
14 | @Test
15 | void testBinaryEmptyCons() {
16 | new BinaryConnectionFactory();
17 | }
18 |
19 | @Test
20 | void testBinaryTwoIntCons() {
21 | new BinaryConnectionFactory(5, 5);
22 | }
23 |
24 | @Test
25 | void testBinaryAnIntAnotherIntAndAHashAlgorithmCons() {
26 | new BinaryConnectionFactory(5, 5,
27 | HashAlgorithm.FNV1_64_HASH);
28 | }
29 |
30 | @Test
31 | void testQueueSizes() {
32 | ConnectionFactory cf = new DefaultConnectionFactory(100, 1024);
33 | assertEquals(100, cf.createOperationQueue().remainingCapacity());
34 | assertEquals(Integer.MAX_VALUE,
35 | cf.createWriteOperationQueue().remainingCapacity());
36 | assertEquals(Integer.MAX_VALUE,
37 | cf.createReadOperationQueue().remainingCapacity());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/ExpectationsUtil.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.util.function.Consumer;
4 |
5 | import org.jmock.Expectations;
6 |
7 | public final class ExpectationsUtil {
8 |
9 | private ExpectationsUtil() {
10 | }
11 |
12 | public static Expectations buildExpectations(Consumer checkList) {
13 | Expectations expectations = new Expectations();
14 | checkList.accept(expectations);
15 | return expectations;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/KetamaConnectionFactoryTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.util.ArrayList;
4 |
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 | import static org.junit.jupiter.api.Assertions.assertTrue;
9 |
10 | /**
11 | * A very basic test that the KetamaConnectionFactory returns both the correct
12 | * hash algorithm and the correct node locator.
13 | */
14 | class KetamaConnectionFactoryTest {
15 |
16 | /*
17 | * This *is* kinda lame, but it tests the specific differences from the
18 | * DefaultConnectionFactory.
19 | */
20 | @Test
21 | void testCorrectTypes() {
22 | ConnectionFactory factory = new KetamaConnectionFactory();
23 |
24 | NodeLocator locator = factory.createLocator(new ArrayList<>());
25 | assertTrue(locator instanceof KetamaNodeLocator);
26 |
27 | assertEquals(HashAlgorithm.KETAMA_HASH, factory.getHashAlg());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/LongClientTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.List;
6 | import java.util.Map;
7 | import java.util.Random;
8 |
9 | import net.spy.memcached.compat.SyncThread;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | import static org.junit.jupiter.api.Assertions.assertEquals;
14 | import static org.junit.jupiter.api.Assertions.assertTrue;
15 |
16 | /**
17 | * Longer running test case.
18 | */
19 | class LongClientTest extends ClientBaseCase {
20 |
21 | @Test
22 | void testParallelGet() throws Throwable {
23 | // Get a connection with the get optimization disabled.
24 | client.shutdown();
25 | initClient(new DefaultConnectionFactory() {
26 | @Override
27 | public long getOperationTimeout() {
28 | return 15000;
29 | }
30 |
31 | @Override
32 | public boolean shouldOptimize() {
33 | return false;
34 | }
35 | });
36 |
37 | // Throw in some seed data.
38 | byte data[] = new byte[32768];
39 | Random r = new Random();
40 | r.nextBytes(data);
41 | final int hashcode = Arrays.hashCode(data);
42 | final List keys = new ArrayList<>(50);
43 | for (int i = 0; i < 50; i++) {
44 | keys.add("k" + i);
45 | assertTrue(client.set(keys.get(i), 3600, data).get());
46 | }
47 |
48 | int cnt = SyncThread.getDistinctResultCount(25, () -> {
49 | for (int i = 0; i < 25; i++) {
50 | Map m = client.getBulk(keys);
51 | for (String s : keys) {
52 | byte b[] = (byte[]) m.get(s);
53 | assertEquals(hashcode, Arrays.hashCode(b));
54 | }
55 | }
56 | return hashcode;
57 | });
58 | assertEquals(cnt, 25);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/SocketTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import java.net.SocketException;
4 | import java.util.Collection;
5 |
6 | import org.junit.jupiter.api.BeforeEach;
7 | import org.junit.jupiter.api.Test;
8 |
9 | import static org.junit.jupiter.api.Assertions.assertTrue;
10 |
11 | class SocketTest {
12 | private ArcusClient client;
13 | private final String ZK_STRING = "127.0.0.1:2181";
14 | private final String SERVICE_CODE = "test";
15 |
16 | @BeforeEach
17 | protected void setUp() throws Exception {
18 | ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder();
19 | connectionFactoryBuilder.setKeepAlive(true);
20 | client = ArcusClient.createArcusClient(ZK_STRING, SERVICE_CODE, connectionFactoryBuilder);
21 | }
22 |
23 | @Test
24 | void testSocketKeepAliveTest() throws SocketException {
25 | Collection allNodes =
26 | client.getAllNodes();
27 | for (MemcachedNode node : allNodes) {
28 | assertTrue(node.getChannel().socket().getKeepAlive());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/internal/CompositeExceptionTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.internal;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import net.spy.memcached.ops.OperationErrorType;
7 | import net.spy.memcached.ops.OperationException;
8 |
9 | import org.junit.jupiter.api.Test;
10 |
11 | import static org.junit.jupiter.api.Assertions.assertTrue;
12 |
13 | class CompositeExceptionTest {
14 |
15 | @Test
16 | void printStackTraceOfAllExceptions() {
17 | List exceptions = new ArrayList<>();
18 | exceptions.add(new OperationException(OperationErrorType.SERVER, "msg1"));
19 | exceptions.add(new OperationException(OperationErrorType.CLIENT, "msg2"));
20 | Exception e = throwError1();
21 | exceptions.add(e);
22 | CompositeException compositeException = new CompositeException(exceptions);
23 | String message = compositeException.getCause().getMessage();
24 |
25 | assertTrue(message
26 | .contains("OperationException: SERVER: msg1"));
27 | assertTrue(message
28 | .contains("OperationException: CLIENT: msg2"));
29 | assertTrue(message
30 | .contains("OperationException: SERVER: msg3"));
31 | assertTrue(message
32 | .contains("at net.spy.memcached.internal.CompositeExceptionTest.throwError2"));
33 | assertTrue(message
34 | .contains("at net.spy.memcached.internal.CompositeExceptionTest.throwError1"));
35 | }
36 |
37 | private Exception throwError1() {
38 | return throwError2();
39 | }
40 |
41 | private Exception throwError2() {
42 | return new OperationException(OperationErrorType.SERVER, "msg3");
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/internal/SingleElementInfiniteIteratorTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.internal;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 |
6 | import static org.junit.jupiter.api.Assertions.assertSame;
7 | import static org.junit.jupiter.api.Assertions.assertTrue;
8 | import static org.junit.jupiter.api.Assertions.fail;
9 |
10 | class SingleElementInfiniteIteratorTest {
11 | private static final String CONSTANT = "foo";
12 | private SingleElementInfiniteIterator iterator;
13 |
14 | @BeforeEach
15 | protected void setUp() throws Exception {
16 | iterator = new SingleElementInfiniteIterator<>(CONSTANT);
17 | }
18 |
19 | @Test
20 | void testHasNextAndNext() {
21 | for (int i = 0; i < 100; ++i) {
22 | assertTrue(iterator.hasNext());
23 | assertSame(CONSTANT, iterator.next());
24 | }
25 | }
26 |
27 | @Test
28 | void testRemove() {
29 | try {
30 | iterator.remove();
31 | fail("Expected UnsupportedOperationException on a remove.");
32 | } catch (UnsupportedOperationException e) {
33 | // test success.
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/protocol/ascii/ExtensibleOperationImpl.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.ascii;
2 |
3 | import net.spy.memcached.ops.OperationCallback;
4 |
5 | /**
6 | * For testing, allow subclassing of the operation impl.
7 | */
8 | public abstract class ExtensibleOperationImpl extends OperationImpl {
9 |
10 | public ExtensibleOperationImpl() {
11 | super();
12 | }
13 |
14 | public ExtensibleOperationImpl(OperationCallback cb) {
15 | super(cb);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/protocol/ascii/OperationFactoryTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.ascii;
2 |
3 | import net.spy.memcached.OperationFactory;
4 | import net.spy.memcached.OperationFactoryTestBase;
5 | import net.spy.memcached.ops.Mutator;
6 | import net.spy.memcached.ops.MutatorOperation;
7 |
8 | import org.junit.jupiter.api.Test;
9 |
10 | import static org.junit.jupiter.api.Assertions.assertEquals;
11 | import static org.junit.jupiter.api.Assertions.assertSame;
12 |
13 | class OperationFactoryTest extends OperationFactoryTestBase {
14 |
15 | @Override
16 | protected OperationFactory getOperationFactory() {
17 | return new AsciiOperationFactory();
18 | }
19 |
20 | @Test
21 | @Override
22 | public void testMutatorOperationIncrCloning() {
23 | int exp = 823862;
24 | long def = 28775;
25 | int by = 7735;
26 | MutatorOperation op = ofact.mutate(Mutator.incr, TEST_KEY, by, def,
27 | exp, genericCallback);
28 |
29 | MutatorOperation op2 = cloneOne(MutatorOperation.class, op);
30 | assertKey(op2);
31 | assertEquals(-1, op2.getExpiration());
32 | assertEquals(-1, op2.getDefault());
33 | assertEquals(by, op2.getBy());
34 | assertSame(Mutator.incr, op2.getType());
35 | assertCallback(op2);
36 | }
37 |
38 | @Test
39 | @Override
40 | public void testMutatorOperationDecrCloning() {
41 | int exp = 823862;
42 | long def = 28775;
43 | int by = 7735;
44 | MutatorOperation op = ofact.mutate(Mutator.decr, TEST_KEY, by, def,
45 | exp, genericCallback);
46 |
47 | MutatorOperation op2 = cloneOne(MutatorOperation.class, op);
48 | assertKey(op2);
49 | assertEquals(-1, op2.getExpiration());
50 | assertEquals(-1, op2.getDefault());
51 | assertEquals(by, op2.getBy());
52 | assertSame(Mutator.decr, op2.getType());
53 | assertCallback(op2);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/protocol/binary/OperationFactoryTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.binary;
2 |
3 | import net.spy.memcached.OperationFactory;
4 | import net.spy.memcached.OperationFactoryTestBase;
5 |
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertTrue;
9 |
10 | class OperationFactoryTest extends OperationFactoryTestBase {
11 |
12 | @Override
13 | protected OperationFactory getOperationFactory() {
14 | return new BinaryOperationFactory();
15 | }
16 |
17 | @Test
18 | @Override
19 | public void testMultipleGetsOperationCloning() {
20 | assertTrue(true);
21 | }
22 |
23 | @Test
24 | @Override
25 | public void testMultipleGetsOperationFanout() {
26 | assertTrue(true);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/protocol/binary/OperationTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.protocol.binary;
2 |
3 | import org.junit.jupiter.api.Test;
4 |
5 | import static net.spy.memcached.protocol.binary.OperationImpl.decodeInt;
6 | import static net.spy.memcached.protocol.binary.OperationImpl.decodeUnsignedInt;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 |
10 | /**
11 | * Test operation stuff.
12 | */
13 | class OperationTest {
14 |
15 | @Test
16 | void testIntegerDecode() {
17 | assertEquals(129,
18 | decodeInt(new byte[]{0, 0, 0, (byte) 0x81}, 0));
19 | assertEquals(129 * 256,
20 | decodeInt(new byte[]{0, 0, (byte) 0x81, 0}, 0));
21 | assertEquals(129 * 256 * 256,
22 | decodeInt(new byte[]{0, (byte) 0x81, 0, 0}, 0));
23 | assertEquals(129 * 256 * 256 * 256,
24 | decodeInt(new byte[]{(byte) 0x81, 0, 0, 0}, 0));
25 | }
26 |
27 | @Test
28 | void testUnsignedIntegerDecode() {
29 | assertEquals(129,
30 | decodeUnsignedInt(new byte[]{0, 0, 0, (byte) 0x81}, 0));
31 | assertEquals(129 * 256,
32 | decodeUnsignedInt(new byte[]{0, 0, (byte) 0x81, 0}, 0));
33 | assertEquals(129 * 256 * 256,
34 | decodeUnsignedInt(new byte[]{0, (byte) 0x81, 0, 0}, 0));
35 | assertEquals(129L * 256L * 256L * 256L,
36 | decodeUnsignedInt(new byte[]{(byte) 0x81, 0, 0, 0}, 0));
37 | }
38 |
39 | @Test
40 | void testOperationStatusString() {
41 | String s = String.valueOf(OperationImpl.STATUS_OK);
42 | assertEquals("{OperationStatus success=true: OK}", s);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/transcoders/CachedDataTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.transcoders;
2 |
3 | import net.spy.memcached.CachedData;
4 |
5 | import org.junit.jupiter.api.Test;
6 |
7 | import static org.junit.jupiter.api.Assertions.assertEquals;
8 |
9 | /**
10 | * Test a couple aspects of CachedData.
11 | */
12 | class CachedDataTest {
13 |
14 | @Test
15 | void testToString() throws Exception {
16 | String exp = "{CachedData flags=13 data=[84, 104, 105, 115, 32, 105, "
17 | + "115, 32, 97, 32, 115, 105, 109, 112, 108, 101, 32, 116, 101, "
18 | + "115, 116, 32, 115, 116, 114, 105, 110, 103, 46] eFlag=null }";
19 | CachedData cd = new CachedData(13,
20 | "This is a simple test string.".getBytes("UTF-8"),
21 | CachedData.MAX_SIZE);
22 | assertEquals(exp, String.valueOf(cd));
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/transcoders/IntegerTranscoderTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.transcoders;
2 |
3 | import net.spy.memcached.CachedData;
4 |
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 | import static org.junit.jupiter.api.Assertions.assertNull;
10 |
11 | /**
12 | * Test the integer transcoder.
13 | */
14 | class IntegerTranscoderTest {
15 |
16 | private IntegerTranscoder tc = null;
17 |
18 | @BeforeEach
19 | protected void setUp() throws Exception {
20 | tc = new IntegerTranscoder();
21 | }
22 |
23 | @Test
24 | void testInt() throws Exception {
25 | assertEquals(923, tc.decode(tc.encode(923)).intValue());
26 | }
27 |
28 | @Test
29 | void testBadFlags() throws Exception {
30 | CachedData cd = tc.encode(9284);
31 | assertNull(tc.decode(new CachedData(cd.getFlags() + 1, cd.getData(),
32 | CachedData.MAX_SIZE)));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/transcoders/LongTranscoderTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.transcoders;
2 |
3 | import net.spy.memcached.CachedData;
4 |
5 | import org.junit.jupiter.api.BeforeEach;
6 | import org.junit.jupiter.api.Test;
7 |
8 | import static org.junit.jupiter.api.Assertions.assertEquals;
9 | import static org.junit.jupiter.api.Assertions.assertNull;
10 |
11 | /**
12 | * Test the long transcoder.
13 | */
14 | class LongTranscoderTest {
15 |
16 | private LongTranscoder tc = null;
17 |
18 | @BeforeEach
19 | protected void setUp() throws Exception {
20 | tc = new LongTranscoder();
21 | }
22 |
23 | @Test
24 | void testLong() throws Exception {
25 | assertEquals(923, tc.decode(tc.encode(923L)).longValue());
26 | }
27 |
28 | @Test
29 | void testBadFlags() throws Exception {
30 | CachedData cd = tc.encode(9284L);
31 | assertNull(tc.decode(new CachedData(cd.getFlags() + 1, cd.getData(),
32 | CachedData.MAX_SIZE)));
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/test/java/net/spy/memcached/transcoders/WhalinV1TranscoderTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.transcoders;
2 |
3 | import java.util.Arrays;
4 |
5 | import net.spy.memcached.CachedData;
6 |
7 | import org.junit.jupiter.api.BeforeEach;
8 |
9 | import static org.junit.jupiter.api.Assertions.assertNotNull;
10 | import static org.junit.jupiter.api.Assertions.assertTrue;
11 |
12 | class WhalinV1TranscoderTest extends BaseTranscoderCase {
13 |
14 | @BeforeEach
15 | protected void setUp() throws Exception {
16 | setTranscoder(new WhalinV1Transcoder());
17 | }
18 |
19 | @Override
20 | void testByteArray() throws Exception {
21 | byte[] a = {'a', 'b', 'c'};
22 |
23 | CachedData cd = getTranscoder().encode(a);
24 | byte[] decoded = (byte[]) getTranscoder().decode(cd);
25 | assertNotNull(decoded);
26 | assertTrue(Arrays.equals(a, decoded));
27 | }
28 |
29 | @Override
30 | protected int getStringFlags() {
31 | // Flags are not used by this transcoder.
32 | return 0;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/ArcusClientConnectTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached;
18 |
19 | import net.spy.memcached.collection.BaseIntegrationTest;
20 |
21 | import org.junit.jupiter.api.Assumptions;
22 | import org.junit.jupiter.api.Test;
23 | import org.junit.jupiter.api.BeforeEach;
24 |
25 | class ArcusClientConnectTest {
26 |
27 | @BeforeEach
28 | protected void setUp() throws Exception {
29 | // This test assumes we use ZK
30 | Assumptions.assumeTrue(BaseIntegrationTest.USE_ZK);
31 | }
32 |
33 | @Test
34 | void testOpenAndWait() {
35 | ArcusClient client = ArcusClient.createArcusClient(BaseIntegrationTest.ZK_ADDRESS,
36 | BaseIntegrationTest.SERVICE_CODE);
37 | client.shutdown();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/ArcusClientNotExistsServiceCodeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached;
18 |
19 | import net.spy.memcached.collection.BaseIntegrationTest;
20 |
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | import static org.junit.jupiter.api.Assertions.fail;
25 |
26 | @Disabled
27 | class ArcusClientNotExistsServiceCodeTest {
28 |
29 | @Test
30 | void testNotExistsServiceCode() {
31 | if (!BaseIntegrationTest.USE_ZK) {
32 | return;
33 | }
34 |
35 | try {
36 | ArcusClient.createArcusClient(BaseIntegrationTest.ZK_ADDRESS, "NOT_EXISTS_SVC_CODE");
37 | } catch (NotExistsServiceCodeException e) {
38 | return;
39 | }
40 | fail("not exists service code test failed.");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/ArcusClientPoolReconnectTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached;
18 |
19 | import net.spy.memcached.collection.BaseIntegrationTest;
20 |
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | @Disabled
25 | class ArcusClientPoolReconnectTest {
26 |
27 | @Test
28 | void testOpenAndWait() {
29 | ArcusClientPool client = ArcusClient.createArcusClientPool(BaseIntegrationTest.ZK_ADDRESS,
30 | BaseIntegrationTest.SERVICE_CODE, 2);
31 |
32 | try {
33 | Thread.sleep(120000L);
34 | } catch (InterruptedException e) {
35 | e.printStackTrace();
36 | }
37 |
38 | client.shutdown();
39 |
40 | try {
41 | Thread.sleep(Long.MAX_VALUE);
42 | } catch (InterruptedException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/ArcusClientReconnectTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached;
18 |
19 | import net.spy.memcached.collection.BaseIntegrationTest;
20 |
21 | import org.junit.jupiter.api.Disabled;
22 | import org.junit.jupiter.api.Test;
23 |
24 | @Disabled
25 | class ArcusClientReconnectTest {
26 |
27 | @Test
28 | void testOpenAndWait() {
29 | if (!BaseIntegrationTest.USE_ZK) {
30 | return;
31 | }
32 |
33 | ArcusClient client = ArcusClient.createArcusClient(BaseIntegrationTest.ZK_ADDRESS,
34 | BaseIntegrationTest.SERVICE_CODE);
35 |
36 | try {
37 | Thread.sleep(120000L);
38 | } catch (InterruptedException e) {
39 | e.printStackTrace();
40 | }
41 |
42 | client.shutdown();
43 |
44 | try {
45 | Thread.sleep(Long.MAX_VALUE);
46 | } catch (InterruptedException e) {
47 | e.printStackTrace();
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/LoggerSetter.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached;
2 |
3 | import net.spy.memcached.compat.log.DefaultLogger;
4 | import net.spy.memcached.compat.log.Log4JLogger;
5 | import net.spy.memcached.compat.log.Logger;
6 | import net.spy.memcached.compat.log.SLF4JLogger;
7 | import net.spy.memcached.compat.log.SunLogger;
8 |
9 | public final class LoggerSetter {
10 | private LoggerSetter() {}
11 |
12 | public static void setLogger(Class logger) {
13 | System.setProperty("net.spy.log.LoggerImpl", logger.getName());
14 | }
15 |
16 | public static void setDefaultLogger() {
17 | setLogger(DefaultLogger.class);
18 | }
19 |
20 | public static void setLog4JLogger() {
21 | setLogger(Log4JLogger.class);
22 | }
23 |
24 | public static void setSLF4JLogger() {
25 | setLogger(SLF4JLogger.class);
26 | }
27 |
28 | public static void setSunLogger() {
29 | setLogger(SunLogger.class);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/collection/attribute/SetAttrTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.collection.attribute;
18 |
19 | import net.spy.memcached.collection.BaseIntegrationTest;
20 |
21 | import org.junit.jupiter.api.Test;
22 |
23 | class SetAttrTest extends BaseIntegrationTest {
24 |
25 | @Test
26 | void testSetAttr() throws Exception {
27 | // TODO: implement
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/emptycollection/ProtocolListGetTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.emptycollection;
18 |
19 | import net.spy.memcached.collection.ListGet;
20 |
21 | import org.junit.jupiter.api.Test;
22 |
23 | import static org.junit.jupiter.api.Assertions.assertEquals;
24 |
25 | class ProtocolListGetTest {
26 |
27 | private static final int index = 10;
28 |
29 | @Test
30 | void testStringify() {
31 | assertEquals("10 drop",
32 | (new ListGet(index, true, true)).stringify());
33 | assertEquals("10 delete", (new ListGet(index, true,
34 | false)).stringify());
35 | assertEquals("10",
36 | (new ListGet(index, false, true)).stringify());
37 | assertEquals("10",
38 | (new ListGet(index, false, false)).stringify());
39 |
40 | assertEquals("10..20 delete", (new ListGet(10, 20, true,
41 | false)).stringify());
42 | assertEquals("10..20 drop", (new ListGet(10, 20, true,
43 | true)).stringify());
44 | assertEquals("10..20",
45 | (new ListGet(10, 20, false, true)).stringify());
46 | assertEquals("10..20",
47 | (new ListGet(10, 20, false, false)).stringify());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/emptycollection/ProtocolMapGetTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2016 JaM2in Co., Ltd.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.emptycollection;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | import net.spy.memcached.collection.MapGet;
23 |
24 | import org.junit.jupiter.api.Test;
25 |
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 |
28 | class ProtocolMapGetTest {
29 |
30 | private final String MKEY = "mkey";
31 |
32 | @Test
33 | void testStringify() {
34 | // default setting : dropIfEmpty = true
35 |
36 | List mkeyList = new ArrayList<>();
37 | mkeyList.add(MKEY);
38 | assertEquals("4 1 drop",
39 | (new MapGet(mkeyList, true, true)).stringify());
40 | assertEquals("4 1 delete",
41 | (new MapGet(mkeyList, true, false)).stringify());
42 | assertEquals("4 1",
43 | (new MapGet(mkeyList, false, true)).stringify());
44 | assertEquals("4 1",
45 | (new MapGet(mkeyList, false, false)).stringify());
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/emptycollection/ProtocolSetExistTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.emptycollection;
18 |
19 | import net.spy.memcached.collection.SetExist;
20 | import net.spy.memcached.transcoders.CollectionTranscoder;
21 | import net.spy.memcached.transcoders.Transcoder;
22 |
23 | import org.junit.jupiter.api.Test;
24 |
25 | import static org.junit.jupiter.api.Assertions.assertArrayEquals;
26 | import static org.junit.jupiter.api.Assertions.assertEquals;
27 |
28 | class ProtocolSetExistTest {
29 | private final Object value = "value";
30 | private final Transcoder testTranscoder = new CollectionTranscoder();
31 |
32 | @Test
33 | void testStringify() {
34 | SetExist exist = new SetExist<>(value, testTranscoder);
35 | assertEquals("5", exist.stringify());
36 | }
37 |
38 | @Test
39 | void testGetAdditionalArgs() {
40 | SetExist exist = new SetExist<>(value, testTranscoder);
41 | assertArrayEquals(new byte[]{'v', 'a', 'l', 'u', 'e'}, exist.getAdditionalArgs());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/emptycollection/ProtocolSetGetTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * arcus-java-client : Arcus Java client
3 | * Copyright 2010-2014 NAVER Corp.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package net.spy.memcached.emptycollection;
18 |
19 | import net.spy.memcached.collection.SetGet;
20 |
21 | import org.junit.jupiter.api.Test;
22 |
23 | import static org.junit.jupiter.api.Assertions.assertEquals;
24 |
25 | class ProtocolSetGetTest {
26 |
27 | private static final int count = 10;
28 |
29 | @Test
30 | void testStringify() {
31 | assertEquals("10 drop",
32 | (new SetGet(count, true, true)).stringify());
33 | assertEquals("10 delete",
34 | (new SetGet(count, true, false)).stringify());
35 | assertEquals("10",
36 | (new SetGet(count, false, true)).stringify());
37 | assertEquals("10",
38 | (new SetGet(count, false, false)).stringify());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/test/AuthTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.test;
2 |
3 | import java.util.Collections;
4 |
5 | import net.spy.memcached.AddrUtil;
6 | import net.spy.memcached.ConnectionFactoryBuilder;
7 | import net.spy.memcached.ConnectionFactoryBuilder.Protocol;
8 | import net.spy.memcached.MemcachedClient;
9 | import net.spy.memcached.auth.AuthDescriptor;
10 | import net.spy.memcached.compat.SpyObject;
11 |
12 | /**
13 | * Authentication functional test.
14 | */
15 | class AuthTest extends SpyObject implements Runnable {
16 |
17 | private final String username;
18 | private final String password;
19 | private MemcachedClient client;
20 |
21 | public AuthTest(String u, String p) {
22 | username = u;
23 | password = p;
24 | }
25 |
26 | public void init() throws Exception {
27 | client = new MemcachedClient(new ConnectionFactoryBuilder()
28 | .setProtocol(Protocol.BINARY)
29 | .setAuthDescriptor(AuthDescriptor.typical(username, password))
30 | .build(), AddrUtil.getAddresses(Collections.singletonList("localhost:11212")));
31 | }
32 |
33 | public void shutdown() throws Exception {
34 | client.shutdown();
35 | }
36 |
37 | public void run() {
38 | System.out.println("Available mechs: " + client.listSaslMechanisms());
39 | try {
40 | Thread.sleep(1000);
41 | } catch (InterruptedException e) {
42 | e.printStackTrace();
43 | }
44 | client.getVersions();
45 | }
46 |
47 | public static void main(String[] a) throws Exception {
48 | AuthTest lt = new AuthTest("testuser", "testpass");
49 | lt.init();
50 | long start = System.currentTimeMillis();
51 | try {
52 | lt.run();
53 | } finally {
54 | lt.shutdown();
55 | }
56 | long end = System.currentTimeMillis();
57 | System.out.println("Runtime: " + (end - start) + "ms");
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/test/MultiNodeFailureTest.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.test;
2 |
3 | import java.util.Arrays;
4 |
5 | import net.spy.memcached.AddrUtil;
6 | import net.spy.memcached.MemcachedClient;
7 |
8 | /**
9 | * This is an attempt to reproduce a problem where a server fails during a
10 | * series of gets.
11 | */
12 | final class MultiNodeFailureTest {
13 |
14 | private MultiNodeFailureTest() {
15 | }
16 |
17 | public static void main(String args[]) throws Exception {
18 | MemcachedClient c = new MemcachedClient(AddrUtil.getAddresses(
19 | Arrays.asList("localhost:11200", " localhost:11201")));
20 | while (true) {
21 | for (int i = 0; i < 1000; i++) {
22 | try {
23 | c.getBulk(Arrays.asList("blah1", "blah2", "blah3", "blah4", "blah5"));
24 | } catch (Exception e) {
25 | e.printStackTrace();
26 | }
27 | }
28 | System.out.println("Did a thousand.");
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/test/manual/net/spy/memcached/test/ObserverToy.java:
--------------------------------------------------------------------------------
1 | package net.spy.memcached.test;
2 |
3 | import java.net.SocketAddress;
4 | import java.util.Collection;
5 | import java.util.Collections;
6 | import java.util.concurrent.TimeUnit;
7 |
8 | import net.spy.memcached.AddrUtil;
9 | import net.spy.memcached.ConnectionObserver;
10 | import net.spy.memcached.DefaultConnectionFactory;
11 | import net.spy.memcached.MemcachedClient;
12 |
13 | /**
14 | * This expects a server on port 11212 that's somewhat unstable so it can report
15 | * and what-not.
16 | */
17 | final class ObserverToy {
18 |
19 | private ObserverToy() {
20 | }
21 |
22 | public static void main(String[] args) throws Exception {
23 | final ConnectionObserver obs = new ConnectionObserver() {
24 | public void connectionEstablished(SocketAddress sa,
25 | int reconnectCount) {
26 | System.out.println("*** Established: " + sa + " count="
27 | + reconnectCount);
28 | }
29 |
30 | public void connectionLost(SocketAddress sa) {
31 | System.out.println("*** Lost connection: " + sa);
32 | }
33 |
34 | };
35 |
36 | MemcachedClient client = new MemcachedClient(new DefaultConnectionFactory() {
37 |
38 | @Override
39 | public Collection getInitialObservers() {
40 | return Collections.singleton(obs);
41 | }
42 |
43 | @Override
44 | public boolean isDaemon() {
45 | return false;
46 | }
47 |
48 | }, AddrUtil.getAddresses(Collections.singletonList("localhost:11212")));
49 |
50 | while (true) {
51 | try {
52 | client.asyncGet("ObserverToy").get(1, TimeUnit.SECONDS);
53 | Thread.sleep(1000);
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | }
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/xdocs/index.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Dustin Sallings
8 | java memcached client
9 |
10 |
11 |
12 |
23 |
24 |
25 |
--------------------------------------------------------------------------------