You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by rv...@apache.org on 2017/01/13 22:46:23 UTC
[39/51] [partial] geode git commit: Software Grant Agreement (SGA)
from Pivotal for Apache Geode
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/cclient/src/gf_client.c
----------------------------------------------------------------------
diff --git a/src/cclient/src/gf_client.c b/src/cclient/src/gf_client.c
new file mode 100644
index 0000000..24a2d1e
--- /dev/null
+++ b/src/cclient/src/gf_client.c
@@ -0,0 +1,805 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include<pthread.h>
+#include "data_io.h"
+#include "gf_client.h"
+
+
+#define RECIEVE_DATA(context, request, reply, len, resultcode) \
+ recieveData(context, &reply, len, resultcode);\
+if(*resultcode != NO_ERROR)\
+{\
+ clearBuf(&request);\
+ clearBuf(&reply);\
+ return;\
+}
+
+#define SEND_DATA(context, request, reply, resultcode) \
+ sendData(context, getBuffer(&request), getBufferLength(&request), resultcode);\
+if(*resultcode != NO_ERROR)\
+{\
+ clearBuf(&request);\
+ clearBuf(&reply);\
+ return;\
+}
+
+
+#define CLIENT_TO_SERVER 100
+#define REPLY_OK 59
+#define SECURITY_CREDENTIALS_NONE 0
+#define VERSION_ORDINAL_651 7 // since NC 3510
+#define CONFLATEBYTE 0
+#define ADDRSIZE 4
+#define DCPORT 12334
+#define VMKIND 13
+#define ROLEARRLENGTH 0
+#define REGION_NAME "/ROOT-REGION"
+#define TIMEOUT 5
+#define RAND_STRING_LEN 10
+const int32_t HEADER_LENGTH = 17;
+static int32_t synch_counter = 2;
+//static int32_t transactioID = 0;
+
+
+#define MAXBUF 1024
+
+enum TypeIdValues {
+ // Do not use IDs 5 and 6 which are used by .NET
+ // ManagedObject and ManagedObjectXml. If those are
+ // required then change those in GemfireTypeIdsM.hpp
+
+ // keep the following in alphabetical order please.
+ Properties = 11,
+ BooleanArray = 26,
+ CharArray = 27,
+ RegionAttributes = 30, // because there's no equivalence in java
+ CacheableUndefined = 31,
+ Struct = 32,
+ NullObj = 41,
+ CacheableString = 42,
+ CacheableBytes = 46,
+ CacheableInt16Array = 47,
+ CacheableInt32Array = 48,
+ CacheableInt64Array = 49,
+ CacheableFloatArray = 50,
+ CacheableDoubleArray = 51,
+ CacheableObjectArray = 52,
+ CacheableBoolean = 53,
+ CacheableWideChar = 54,
+ CacheableByte = 55,
+ CacheableInt16 = 56,
+ CacheableInt32 = 57,
+ CacheableInt64 = 58,
+ CacheableFloat = 59,
+ CacheableDouble = 60,
+ CacheableDate = 61,
+ CacheableFileName = 63,
+ CacheableStringArray = 64,
+ CacheableArrayList = 65,
+ CacheableHashSet = 66,
+ CacheableHashMap = 67,
+ CacheableTimeUnit = 68,
+ CacheableNullString = 69,
+ CacheableHashTable = 70,
+ CacheableVector = 71,
+ CacheableIdentityHashMap = 72,
+ CacheableLinkedHashSet = 73,
+ CacheableStack = 74,
+ CacheableASCIIString = 87,
+ CacheableASCIIStringHuge = 88,
+ CacheableStringHuge = 89
+};
+enum IdValues {
+ // keep the following in alphabetical order please.
+ ObjectTypeImpl = -61,
+ StructTypeImpl = -60,
+ CollectionTypeImpl = -59,
+ FixedIDDefault = 0,
+ FixedIDByte = 1,
+ FixedIDShort = 2,
+ FixedIDInt = 3,
+ FixedIDNone = 4,
+ CacheableToken = 14, // because there's no equivalence in java
+ CacheableObjectPartList = 25,
+ EventId = 36,
+ InterestResultPolicy = 37,
+ ClientProxyMembershipId = 38,
+ CacheableUserData4 = 37,
+ CacheableUserData2 = 38,
+ CacheableUserData = 39,
+ CacheableUserClass = 40,
+ Class = 43,
+ JavaSerializable = 44,
+ DataSerializable = 45,
+ InternalDistributedMember = 92,
+ EntryEventImpl = 105,
+ RegionEventImpl = 108,
+ ClientHealthStats = -126,
+ GatewayEventCallbackArgument = -56, // 0xC8
+ ClientConnectionRequest = -53,
+ ClientConnectionResponse = -50,
+ QueueConnectionRequest = -52,
+ QueueConnectionResponse = -49,
+ LocatorListRequest = -54,
+ LocatorListResponse = -51,
+ GetAllServersRequest = -43,
+ GetAllServersResponse = -42,
+ ClientReplacementRequest= -48
+};
+typedef enum {
+ /* Server couldn't read message; handle it like a server side
+ exception that needs retries */
+ INVALID = -1,
+ REQUEST = 0,
+ RESPONSE /* 1 */,
+ EXCEPTION /* 2 */,
+ REQUEST_DATA_ERROR /* 3 */,
+ DATA_NOT_FOUND_ERROR /* 4 Not in use */,
+ PING /* 5 */,
+ REPLY /* 6 */,
+ PUT /* 7 */,
+ PUT_DATA_ERROR /* 8 */,
+ DESTROY /* 9 */,
+ DESTROY_DATA_ERROR /* 10 */,
+ DESTROY_REGION /* 11 */,
+ DESTROY_REGION_DATA_ERROR /* 12 */,
+ CLIENT_NOTIFICATION /* 13 */,
+ UPDATE_CLIENT_NOTIFICATION /* 14 */,
+ LOCAL_INVALIDATE /* 15 */,
+ LOCAL_DESTROY /* 16 */,
+ LOCAL_DESTROY_REGION /* 17 */,
+ CLOSE_CONNECTION /* 18 */,
+ PROCESS_BATCH /* 19 */,
+ REGISTER_INTEREST /* 20 */,
+ REGISTER_INTEREST_DATA_ERROR /* 21 */,
+ UNREGISTER_INTEREST /* 22 */,
+ UNREGISTER_INTEREST_DATA_ERROR /* 23 */,
+ REGISTER_INTEREST_LIST /* 24 */,
+ UNREGISTER_INTEREST_LIST /* 25 */,
+ UNKNOWN_MESSAGE_TYPE_ERROR /* 26 */,
+ LOCAL_CREATE /* 27 */,
+ LOCAL_UPDATE /* 28 */,
+ CREATE_REGION /* 29 */,
+ CREATE_REGION_DATA_ERROR /* 30 */,
+ MAKE_PRIMARY /* 31 */,
+ RESPONSE_FROM_PRIMARY /* 32 */,
+ RESPONSE_FROM_SECONDARY /* 33 */,
+ QUERY /* 34 */,
+ QUERY_DATA_ERROR /* 35 */,
+ CLEAR_REGION /* 36 */,
+ CLEAR_REGION_DATA_ERROR /* 37 */,
+ CONTAINS_KEY /* 38 */,
+ CONTAINS_KEY_DATA_ERROR /* 39 */,
+ KEY_SET /* 40 */,
+ KEY_SET_DATA_ERROR /* 41 */,
+ EXECUTECQ_MSG_TYPE /* 42 */,
+ EXECUTECQ_WITH_IR_MSG_TYPE /*43 */,
+ STOPCQ_MSG_TYPE /*44*/,
+ CLOSECQ_MSG_TYPE /*45 */,
+ CLOSECLIENTCQS_MSG_TYPE /*46*/,
+ CQDATAERROR_MSG_TYPE /*47 */,
+ GETCQSTATS_MSG_TYPE /*48 */,
+ MONITORCQ_MSG_TYPE /*49 */,
+ CQ_EXCEPTION_TYPE /*50 */,
+ REGISTER_INSTANTIATORS = 51 /* 51 */,
+ PERIODIC_ACK = 52 /* 52 */,
+ CLIENT_READY /* 53 */,
+ CLIENT_MARKER /* 54 */,
+ INVALIDATE_REGION /* 55 */,
+ PUTALL /* 56 */,
+ GET_ALL = 57 /* 57 */,
+ GET_ALL_DATA_ERROR /* 58 */,
+ EXECUTE_REGION_FUNCTION = 59 /* 59 */,
+ EXECUTE_REGION_FUNCTION_RESULT /* 60 */,
+ EXECUTE_REGION_FUNCTION_ERROR /* 61 */,
+ EXECUTE_FUNCTION /* 62 */,
+ EXECUTE_FUNCTION_RESULT /* 63 */,
+ EXECUTE_FUNCTION_ERROR /* 64 */,
+ CLIENT_REGISTER_INTEREST = 65 /* 65 */,
+ CLIENT_UNREGISTER_INTEREST = 66,
+ REGISTER_DATASERIALIZERS = 67,
+ REQUEST_EVENT_VALUE = 68,
+ REQUEST_EVENT_VALUE_ERROR = 69, /*69*/
+ PUT_DELTA_ERROR = 70, /*70*/
+ GET_CLIENT_PR_METADATA = 71, /*71*/
+ RESPONSE_CLIENT_PR_METADATA = 72, /*72*/
+ GET_CLIENT_PARTITION_ATTRIBUTES = 73, /*73*/
+ RESPONSE_CLIENT_PARTITION_ATTRIBUTES =74, /*74*/
+ GET_CLIENT_PR_METADATA_ERROR = 75, /*75*/
+ GET_CLIENT_PARTITION_ATTRIBUTES_ERROR = 76, /*76*/
+ USER_CREDENTIAL_MESSAGE = 77,
+ REMOVE_USER_AUTH = 78,
+ QUERY_WITH_PARAMETERS = 80
+
+} MsgType;
+/*
+int32_t incTransactionID()
+{
+ return 1;//transactioID++;
+}
+*/
+int64_t getAndIncEid(CONTEXT* context)
+{
+ return context->eidSeq++;
+}
+
+void printData(uint8_t* buf, int32_t len)
+{
+ int32_t i;
+ printf("\n");
+ for(i = 0; i < len; i++)
+ {
+ printf("%d ", buf[i]);
+ }
+ printf("\n");
+}
+
+void recieveData(CONTEXT* context, Buffer* buf, uint32_t len, int32_t* resultcode)
+{
+ time_t startTime = time(NULL);
+ uint32_t origLen = len;
+
+ while(len > 0 && (time(NULL) - startTime) < TIMEOUT )
+ {
+ int8_t buffer[MAXBUF];
+ bzero(buffer, MAXBUF);
+ int32_t recLen = recv(context->sockfd, buffer, len > MAXBUF?MAXBUF:len, 0);
+ if(recLen > 0)
+ {
+ len -= recLen;
+ writeBytesOnly(buf, buffer, recLen);
+ } else if(recLen == 0)
+ {
+ *resultcode = CONNECTION_ERROR;
+ //printf("closed connection");
+ return;
+ }
+ }
+
+ //printf("recieve");
+ //printData(getBuffer(buf), getBufferLength(buf));
+
+ if(len == 0)
+ rewindCursor(buf, origLen);
+ *resultcode = (len > 0)?CONNECTION_ERROR:NO_ERROR;
+}
+
+
+
+void sendData(CONTEXT* context, uint8_t* buf, int32_t len, int32_t* resultcode)
+{
+ time_t startTime = time(NULL);
+ uint32_t sentLen = 0;
+ //printf("send[%d]", len);
+ //printData(buf, len);
+ while(len > 0 && (time(NULL) - startTime) < TIMEOUT )
+ {
+ int32_t sendLen = send(context->sockfd, (buf + sentLen), len, 0);
+ //printf("sent %d bytes\n", sendLen);
+ if(sendLen > 0)
+ {
+ len -= sendLen;
+ sentLen += sendLen;
+ } else if(sendLen == 0)
+ {
+ *resultcode = CONNECTION_ERROR;
+ //printf("closed connection");
+ return;
+ }
+
+ }
+
+ *resultcode = (len > 0)?CONNECTION_ERROR:NO_ERROR;
+}
+
+CONTEXT* createContext(char* host, char* port)
+{
+
+ struct addrinfo hints;
+ struct addrinfo *result, *rp;
+ int sfd, s;
+
+ /* Obtain address(es) matching host/port */
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = 0;
+ hints.ai_protocol = 0;
+
+ s = getaddrinfo(host, port, &hints, &result);
+ if (s != 0) {
+ return NULL;
+ }
+
+ /* getaddrinfo() returns a list of address structures.
+ Try each address until we successfully connect(2).
+ If socket(2) (or connect(2)) fails, we (close the socket
+ and) try the next address. */
+
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
+ sfd = socket(rp->ai_family, rp->ai_socktype,
+ rp->ai_protocol);
+ struct timeval tv;
+ int32_t timeout=1000;
+
+ tv.tv_sec = timeout / 1000 ;
+ tv.tv_usec = ( timeout % 1000) * 1000 ;
+
+ setsockopt (sfd, SOL_SOCKET, SO_RCVTIMEO, (char
+ *)&tv, sizeof tv);
+ if (sfd == -1)
+ continue;
+
+ if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1)
+ break; /* Success */
+
+ close(sfd);
+ }
+
+ if (rp == NULL) { /* No address succeeded */
+ //fprintf(stderr, "Could not connect\n");
+ //exit(EXIT_FAILURE);
+ return NULL;
+ }
+
+ CONTEXT* context = (CONTEXT*)malloc(sizeof(CONTEXT));
+ context->sockfd = sfd;
+ context->eidSeq = 0;
+
+ return context;
+}
+
+void createRandString(char *randString)
+{
+ const char selectChars[] =
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
+ const uint32_t numChars = (sizeof(selectChars) / sizeof(char)) - 1;
+ strcpy(randString, "GFNative_");
+ uint32_t startIndex = strlen(randString);
+ uint32_t seed = getpid() + time(NULL);
+ srand(seed);
+ uint32_t index;
+ for (index = 0; index < RAND_STRING_LEN; ++index) {
+ randString[startIndex + index] = selectChars[rand() % numChars];
+ }
+ randString[startIndex + RAND_STRING_LEN] = '\0';
+}
+
+void writeClientProxyMembershipId(Buffer* buf)
+{
+ struct hostent *host; /* host information */
+ //struct in_addr h_addr; /* internet address */
+ char hostName[1024];
+ gethostname(hostName, 1023);
+ host = gethostbyname(hostName);
+ char randString[1024];
+ createRandString(randString);
+
+ Buffer memId;
+ initBuf(&memId);
+
+ writeByte(&memId, (int8_t)FixedIDByte);
+ writeByte(&memId, (int8_t)InternalDistributedMember);
+ writeArrayLen(&memId, ADDRSIZE);
+ writeInt(&memId, (int32_t)(*(host->h_addr_list[0])));
+ //m_memID.writeInt((int32_t)hostPort);
+ writeInt(&memId, (int32_t)synch_counter);
+ writeByte(&memId, (int8_t)CacheableASCIIString);
+ writeASCII(&memId, host->h_name );
+ writeByte(&memId, (int8_t)0); // splitbrain flags
+
+ writeInt(&memId, (int32_t)DCPORT);
+
+ writeInt(&memId, (int32_t)getpid());
+ writeByte(&memId, (int8_t)VMKIND);
+ writeArrayLen(&memId, ROLEARRLENGTH);
+ writeByte(&memId, (int8_t)CacheableASCIIString);
+ writeASCII(&memId, "default_GemfireDS");
+ writeByte(&memId, (int8_t)CacheableASCIIString);
+ writeASCII(&memId, randString);
+ writeByte(&memId, (int8_t)CacheableASCIIString);
+ writeASCII(&memId, "");
+ writeInt(&memId, (int32_t)300);
+ writeUnsignedBytes(buf, getBuffer(&memId), getBufferLength(&memId));
+
+
+ clearBuf(&memId);
+}
+
+void doHandshake(CONTEXT* context, int32_t* resultcode)
+{
+ Buffer request;
+ initBuf(&request);
+ Buffer reply;
+ initBuf(&reply);
+ *resultcode = NO_ERROR;
+
+ writeByte(&request, (int8_t)CLIENT_TO_SERVER );
+ writeByte(&request, (int8_t)VERSION_ORDINAL_651);
+ writeByte(&request, (int8_t)REPLY_OK);
+ writeInt(&request, (int32_t)0x7fffffff - 10000 );
+ // Write header for byte FixedID since GFE 5.7
+ writeByte(&request, (int8_t)FixedIDByte);
+ //Writing byte for ClientProxyMembershipID class id=38 as registered on the java server.
+ writeByte(&request, (int8_t)ClientProxyMembershipId);
+ /* calc memId */
+ writeClientProxyMembershipId(&request);
+ // writeBytes(&request, (int8_t *)memIdBuffer, memIdBufferLength);
+ writeInt(&request,(int32_t)1);
+ writeByte(&request, (int8_t)CONFLATEBYTE);
+ writeUnsigned(&request, (uint8_t)SECURITY_CREDENTIALS_NONE);
+
+ SEND_DATA(context, request, reply, resultcode)
+
+ //sendData(context, getBuffer(&buf), getBufferLength(&buf));
+ /*---Get "Hello?"---*/
+ //int recLen = 1;
+ // recieveData(context, &reply, 7);
+ RECIEVE_DATA(context, request, reply, 7, resultcode)
+
+ int8_t acceptance_code;
+ int8_t serverQueueStatus;
+ int8_t recvMsgLenByte;
+ int32_t queueSize;
+ readByte(&reply, &acceptance_code);
+ readByte(&reply, &serverQueueStatus);
+ readInt(&reply, &queueSize);
+ readByte(&reply, &recvMsgLenByte);
+ int32_t recvMsgLen = recvMsgLenByte;
+ if (recvMsgLen== -2) {
+ int16_t recvMsgLenShort = 0;
+ // recieveData(context, &reply, 2);
+ RECIEVE_DATA(context, request, reply, 2, resultcode)
+ readShort(&reply, &recvMsgLenShort);
+ recvMsgLen = recvMsgLenShort;
+ }
+ else if (recvMsgLen == -3) {
+ // recieveData(context, &reply, 4);
+ RECIEVE_DATA(context, request, reply, 4, resultcode)
+ readInt(&reply, &recvMsgLen);
+ }
+ //recieveData(context, &reply, recvMsgLen);
+ RECIEVE_DATA(context, request, reply, recvMsgLen, resultcode)
+ advanceCursor(&reply, recvMsgLen);
+ uint16_t recvMsgLen2 = 0;
+ //recieveData(context, &reply, 2);
+ RECIEVE_DATA(context, request, reply,2, resultcode)
+ readUnsignedShort(&reply, &recvMsgLen2);
+ //recieveData(context, &reply, recvMsgLen2);
+ RECIEVE_DATA(context, request, reply, recvMsgLen2, resultcode)
+ advanceCursor(&reply, recvMsgLen2);
+ int8_t isDeltaEnabledOnServer;
+ //recieveData(context, &reply, 1);
+ RECIEVE_DATA(context, request, reply, 1, resultcode)
+ readByte(&reply, &isDeltaEnabledOnServer);
+ if(acceptance_code != REPLY_OK)
+ {
+ *resultcode = HANDSHAKE_ERROR;
+ }
+ clearBuf(&request);
+ clearBuf(&reply);
+}
+
+
+void gf_write_header(Buffer* buf, uint32_t msgType, uint32_t numOfParts)
+{
+
+ writeInt(buf, (int32_t)msgType);
+ writeInt(buf, (int32_t)0); // write a dummy message len('0' here). At the end write the length at the (buffer + 4) offset.
+ writeInt(buf, (int32_t)numOfParts);
+ writeInt(buf, (int32_t)1);
+ writeByte(buf, (int8_t)0x0);
+}
+
+void write_region_part(Buffer* buf, char* regionName)
+{
+ int32_t len = strlen(regionName);
+ writeInt(buf, len);
+ writeByte(buf, (int8_t)0); // isObject = 0
+ writeBytesOnly(buf, (int8_t *)regionName, len);
+}
+
+void write_null_object(Buffer* buf)
+{
+ //write size
+ writeInt(buf, (int32_t)1);
+ //write isobject
+ writeByte(buf, (int8_t)1);
+ //write actual object
+ writeByte(buf, (int8_t)NullObj);
+}
+
+void write_int_part(Buffer* buf, int32_t intValue)
+{
+ writeInt(buf, (int32_t) 4);
+ writeByte(buf, (int8_t) 0);
+ writeInt(buf, intValue);
+}
+
+void write_string_part(Buffer* buf, const char* strValue)
+{
+ //write size
+ writeInt(buf, (int32_t)0);
+ //write isobject
+ writeByte(buf, (int8_t)1);
+ int32_t before = getBufferLength(buf);
+ writeByte(buf, (int8_t)CacheableASCIIString);
+ writeASCII(buf, strValue);
+ int32_t after = getBufferLength(buf);
+ int32_t sizeOfObj = after - before;
+ rewindCursor(buf, sizeOfObj + 1 + 4);
+ writeInt(buf, sizeOfObj);
+ advanceCursor(buf, sizeOfObj + 1);
+}
+
+void write_bool_part(Buffer* buf, int8_t boolValue)
+{
+ //write size
+ writeInt(buf, (int32_t)2);
+ //write isobject
+ writeByte(buf, (int8_t)1);
+ writeByte(buf, (int8_t)CacheableBoolean);
+ writeByte(buf, (int8_t)boolValue);
+}
+
+void write_bytes_part(Buffer* buf, const int8_t* bytes, int32_t len)
+{
+ //write size
+ writeInt(buf, (int32_t)1);
+ //write isobject
+ writeByte(buf, (int8_t)0);
+ int32_t before = getBufferLength(buf);
+ writeBytesOnly(buf, bytes, len);
+ int32_t after = getBufferLength(buf);
+ int32_t sizeOfObj = after - before;
+ rewindCursor(buf, sizeOfObj + 1 + 4);
+ writeInt(buf, sizeOfObj);
+ advanceCursor(buf, sizeOfObj + 1);
+}
+
+void write_id_part(CONTEXT* context, Buffer* buf)
+{
+ // Write EventId threadid and seqno.
+ int32_t idsBufferLength = 18;
+ writeInt(buf, idsBufferLength);
+ writeUnsigned(buf, (uint8_t) 0);
+ char longCode = 3;
+ writeUnsigned(buf, (uint8_t) longCode);
+ writeLong(buf, pthread_self());
+ writeUnsigned(buf, (uint8_t) longCode);
+ writeLong(buf, getAndIncEid(context));
+}
+
+void write_message_length(Buffer* buf)
+{
+ uint32_t totalLen = getBufferLength(buf);
+ uint32_t g_headerLen = 17;
+ uint32_t msgLen = totalLen - g_headerLen;
+ //printf("msglen: %d\n", msgLen);
+ rewindCursor(buf, totalLen - 4); // msg len is written after the msg type which is of 4 bytes ...
+ writeInt(buf, (int32_t)msgLen);
+ advanceCursor(buf, totalLen - 8); // after writing 4 bytes for msg len you are already 8 bytes ahead from the beginning.
+}
+
+void gf_put(CONTEXT * context, const char * uuid, const int8_t * data, int32_t len, int32_t * resultcode)
+{
+ Buffer request;
+ initBuf(&request);
+ Buffer reply;
+ initBuf(&reply);
+ *resultcode = NO_ERROR;
+
+ gf_write_header(&request, PUT, 7);
+ write_region_part(&request, REGION_NAME);
+ write_null_object(&request);
+ write_int_part(&request, 0);
+ write_string_part(&request, uuid);
+ write_bool_part(&request, 0);
+ write_bytes_part(&request, data, len);
+ write_id_part(context, &request);
+ write_message_length(&request);
+
+ SEND_DATA(context, request, reply, resultcode)
+ // int err = sendData(context, getBuffer(&buf), getBufferLength(&buf));
+ /*---Get "Hello?"---*/
+ //int recLen = 1;
+
+ RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode)
+ //err = recieveData(context, &reply, HEADER_LENGTH);
+ //printf("put error: %d\n", *resultcode);
+ int32_t msgType;
+ int32_t msgLen;
+
+ readInt(&reply, &msgType);
+ readInt(&reply, &msgLen);
+ advanceCursor(&reply, HEADER_LENGTH - 8);
+
+ RECIEVE_DATA(context, request, reply, msgLen, resultcode)
+ if(msgType != REPLY)
+ {
+ *resultcode = OPERATION_ERROR;
+ clearBuf(&request);
+ clearBuf(&reply);
+ }
+ //err = recieveData(context, &reply, msgLen);
+}
+
+void gf_get(CONTEXT * context, const char * uuid, int8_t* data, uint32_t len, int32_t * resultcode)
+{
+ Buffer request;
+ initBuf(&request);
+ Buffer reply;
+ initBuf(&reply);
+ *resultcode = NO_ERROR;
+
+ gf_write_header(&request, REQUEST, 2);
+ write_region_part(&request, REGION_NAME);
+ write_string_part(&request, uuid);
+ write_message_length(&request);
+
+ SEND_DATA(context, request, reply, resultcode)
+
+ //int err = sendData(context, getBuffer(&buf), getBufferLength(&buf));
+
+ RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode)
+ //err = recieveData(context, &reply, HEADER_LENGTH);
+ int32_t msgType;
+ int32_t msgLen;
+
+ readInt(&reply, &msgType);
+ readInt(&reply, &msgLen);
+ advanceCursor(&reply, HEADER_LENGTH - 8);
+
+ //err = recieveData(context, &reply, msgLen);
+ RECIEVE_DATA(context, request, reply, msgLen, resultcode)
+ if(msgType != RESPONSE)
+ {
+ *resultcode = OPERATION_ERROR;
+ clearBuf(&request);
+ clearBuf(&reply);
+ return;
+ }
+ uint32_t dataLen;
+ readUnsignedInt(&reply, &dataLen);
+ int8_t isObj;
+ readByte(&reply, &isObj);
+ memcpy(data, getCursor(&reply), dataLen);
+}
+
+void gf_destroy(CONTEXT * context, const char * uuid, int32_t * resultcode)
+{
+ Buffer request;
+ initBuf(&request);
+ Buffer reply;
+ initBuf(&reply);
+ *resultcode = NO_ERROR;
+
+ gf_write_header(&request, DESTROY, 5);
+ write_region_part(&request, REGION_NAME);
+ write_string_part(&request, uuid);
+ write_null_object(&request);
+ write_null_object(&request);
+ write_id_part(context, &request);
+ write_message_length(&request);
+
+ SEND_DATA(context, request, reply, resultcode)
+
+ // int err = sendData(context, getBuffer(&buf), getBufferLength(&buf));
+ /*---Get "Hello?"---*/
+ //int recLen = 1;
+
+ RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode)
+
+ // err = recieveData(context, &reply, HEADER_LENGTH);
+ //printf("destroy error: %d\n", *resultcode);
+ int32_t msgType;
+ int32_t msgLen;
+
+ readInt(&reply, &msgType);
+ readInt(&reply, &msgLen);
+ advanceCursor(&reply, HEADER_LENGTH - 8);
+
+ // err = recieveData(context, &reply, msgLen);
+ RECIEVE_DATA(context, request, reply, msgLen, resultcode)
+ if(msgType != REPLY)
+ {
+ *resultcode = OPERATION_ERROR;
+ clearBuf(&request);
+ clearBuf(&reply);
+ }
+}
+
+void gf_ping(CONTEXT* context, int32_t* resultcode)
+{
+ Buffer request;
+ initBuf(&request);
+ Buffer reply;
+ initBuf(&reply);
+ *resultcode = NO_ERROR;
+
+ writeInt(&request, (int32_t)PING);
+ writeInt(&request, (int32_t)0);// 17 is fixed message len ... PING only has a header.
+ writeInt(&request, (int32_t)0);// Number of parts.
+ writeInt(&request, (int32_t)0);
+ writeByte(&request, (int8_t)0);// Early ack is '0'.
+ SEND_DATA(context, request, reply, resultcode)
+ RECIEVE_DATA(context, request, reply, HEADER_LENGTH, resultcode)
+
+ int32_t msgType;
+ int32_t msgLen;
+
+ readInt(&reply, &msgType);
+ readInt(&reply, &msgLen);
+ advanceCursor(&reply, HEADER_LENGTH - 8);
+
+ // err = recieveData(context, &reply, msgLen);
+ RECIEVE_DATA(context, request, reply, msgLen, resultcode)
+ if(msgType != REPLY)
+ {
+ *resultcode = OPERATION_ERROR;
+ clearBuf(&request);
+ clearBuf(&reply);
+ }
+}
+
+void gf_disconnect(CONTEXT * context, int32_t * resultcode)
+{
+ Buffer request;
+ initBuf(&request);
+ Buffer reply;
+ initBuf(&reply);
+ *resultcode = NO_ERROR;
+
+ writeInt(&request, (int32_t)CLOSE_CONNECTION);
+ writeInt(&request,(int32_t)6);
+ writeInt(&request,(int32_t)1);// Number of parts.
+ //int32_t txId = TcrMessage::m_transactionId++;
+ writeInt(&request,(int32_t)0);
+ writeByte(&request, (int8_t)0);// Early ack is '0'.
+ // last two parts are not used ... setting zero in both the parts.
+ writeInt(&request,(int32_t)1); // len is 1
+ writeByte(&request,(int8_t)0);// is obj is '0'.
+ // cast away constness here since we want to modify this
+ writeByte(&request,(int8_t)0);// keepalive is '0'.
+ SEND_DATA(context, request, reply, resultcode)
+
+ int32_t error = close(context->sockfd);
+ if(error == 0) {
+ *resultcode = NO_ERROR;
+ } else {
+ *resultcode = CONNECTION_ERROR;
+ }
+
+ free(context);
+}
+
+CONTEXT* gf_connect(char* host, char* port, int32_t* resultcode)
+{
+ CONTEXT* context = createContext(host, port);
+
+ if(context == NULL)
+ {
+ *resultcode = CONNECTION_ERROR;
+ //printf("CONNECTION ERROR");
+ } else {
+ doHandshake(context, resultcode);
+ if(*resultcode != NO_ERROR)
+ {
+ int32_t error;
+ //printf("HANDSHAKE ERROR");
+ *resultcode = HANDSHAKE_ERROR;
+ gf_disconnect(context, &error);
+ context = NULL;
+ }
+ }
+
+ return context;
+}
+
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/cclient/src/gf_client.h
----------------------------------------------------------------------
diff --git a/src/cclient/src/gf_client.h b/src/cclient/src/gf_client.h
new file mode 100644
index 0000000..1728d2e
--- /dev/null
+++ b/src/cclient/src/gf_client.h
@@ -0,0 +1,88 @@
+#ifndef __C_GEMFIRE_CLIENT_H__
+#define __C_GEMFIRE_CLIENT_H__
+
+#include <stdint.h>
+
+typedef struct
+{
+ int32_t sockfd;
+ int64_t eidSeq;
+} CONTEXT;
+
+
+enum error_codes {
+ NO_ERROR,
+ CONNECTION_ERROR = 1,
+ HANDSHAKE_ERROR,
+ OPERATION_ERROR
+};
+
+/*
+ * Establish a connection with the specified GemFire endpoint.
+ *
+ * @param host the hostname to connect.
+ * @param port the port to connect.
+ * @param resultcode the result code returned to the caller.
+ * @returns a pointer to the context required for further operations.
+ */
+
+CONTEXT* gf_connect(char * host, char* port, int32_t * resultcode);
+
+/*
+ * Close down a connection previously established with a GemFire endpoint.
+ *
+ * @param CONTEXT the context of the connection to close.
+ * @param resultcode the result code returned to the caller.
+ */
+
+void gf_disconnect(CONTEXT * context, int32_t * resultcode);
+
+/*
+ * Store data associated with the specified UUID into the GemFire system.
+ * Callee does not free the data.
+ *
+ * @param CONTEXT the context of the connection to use.
+ * @param region the GemFire region where the data goes.
+ * @param uuid the UUID key associated with the data.
+ * @param data a pointer to the data to store.
+ * @param len the byte length of the data.
+ * @param resultcode the result code returned to the caller.
+ */
+
+void gf_put(CONTEXT * context, const char * uuid, const int8_t * data, int32_t len, int32_t * resultcode);
+
+/*
+ * Read data associated with the specified UUID from GemFire.
+ * Caller must free the returned data.
+ *
+ * @param CONTEXT the context of the connection to use.
+ * @param region the GemFire region from where the data is retrieved.
+ * @param uuid the UUID key associated with the data.
+ * @param len the byte length of the data being returned.
+ * @param resultcode the result code returned to the caller.
+ */
+
+void gf_get(CONTEXT * context, const char * uuid, int8_t* data, uint32_t len, int32_t * resultcode);
+
+/*
+ * Destroy the data associated with the specified UUID key from the GemFire system.
+ *
+ * @param CONTEXT the context of the connection to use.
+ * @param region the GemFire region from where the data is cleared.
+ * @param uuid the UUID key associated with the data.
+ * @param resultcode the result code returned to the caller.
+ */
+
+void gf_destroy(CONTEXT * context, const char * uuid, int32_t * resultcode);
+
+/*
+ * Send a ping message to the server
+ *
+ * @param CONTEXT the context of the connection to use.
+ * @param resultcode the result code returned to the caller.
+ */
+
+void gf_ping(CONTEXT* context, int32_t* resultcode);
+
+#endif
+
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/.clang-format
----------------------------------------------------------------------
diff --git a/src/clicache/.clang-format b/src/clicache/.clang-format
new file mode 100644
index 0000000..23a15d5
--- /dev/null
+++ b/src/clicache/.clang-format
@@ -0,0 +1,5 @@
+# C++/CLI sources not supported in clang-format
+---
+Language: Cpp
+DisableFormat: true
+SortIncludes: false
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/clicache/CMakeLists.txt b/src/clicache/CMakeLists.txt
new file mode 100644
index 0000000..e7da90b
--- /dev/null
+++ b/src/clicache/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.4)
+project(clicache_src)
+
+add_subdirectory(src)
+add_subdirectory(integration-test)
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/include/gfcli/Utils.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/include/gfcli/Utils.hpp b/src/clicache/include/gfcli/Utils.hpp
new file mode 100644
index 0000000..39698e2
--- /dev/null
+++ b/src/clicache/include/gfcli/Utils.hpp
@@ -0,0 +1,81 @@
+/*=========================================================================
+ * Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+
+
+
+#pragma once
+
+#include <gfcpp/gf_base.hpp>
+#include "gf_defs.hpp"
+//#include "SystemProperties.hpp"
+//#include "../../impl/NativeWrapper.hpp"
+//#include "../../Log.hpp"
+
+using namespace System;
+using namespace System::Reflection;
+
+namespace GemStone
+{
+ namespace GemFire
+ {
+ namespace Cache
+ {
+ namespace Generic
+ {
+
+ /// <summary>
+ /// Some static utility methods.
+ /// </summary>
+ public ref class Utils STATICCLASS
+ {
+ public:
+
+ /// <summary>
+ /// Load a method from the given assembly path using the default
+ /// constructor (if not a static method) of the given type.
+ /// </summary>
+ /// <param name="assemblyPath">The path of the assembly.</param>
+ /// <param name="typeName">
+ /// The name of the class containing the method.
+ /// </param>
+ /// <param name="methodName">The name of the method.</param>
+ /// <returns>
+ /// The <c>System.Reflection.MethodInfo</c> for the given method,
+ /// or null if the method is not found.
+ /// </returns>
+ static MethodInfo^ LoadMethod( String^ assemblyPath,
+ String^ typeName, String^ methodName);
+
+ /// <summary>
+ /// Load a method from the given assembly name using the default
+ /// constructor (if not a static method) of the given type.
+ /// </summary>
+ /// <param name="assemblyName">The name of the assembly.</param>
+ /// <param name="typeName">
+ /// The name of the class containing the method.
+ /// </param>
+ /// <param name="methodName">The name of the method.</param>
+ /// <returns>
+ /// The <c>System.Reflection.MethodInfo</c> for the given method,
+ /// or null if the method is not found.
+ /// </returns>
+ static MethodInfo^ LoadMethodFrom( String^ assemblyName,
+ String^ typeName, String^ methodName);
+
+ /// <summary>
+ /// Utility method to get the calling thread's last system error code.
+ /// </summary>
+ static property int32_t LastError
+ {
+ int32_t get( );
+ }
+ };
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/integration-test/AckMixTests.cs
----------------------------------------------------------------------
diff --git a/src/clicache/integration-test/AckMixTests.cs b/src/clicache/integration-test/AckMixTests.cs
new file mode 100644
index 0000000..a758002
--- /dev/null
+++ b/src/clicache/integration-test/AckMixTests.cs
@@ -0,0 +1,254 @@
+//=========================================================================
+// Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+// This product is protected by U.S. and international copyright
+// and intellectual property laws. Pivotal products are covered by
+// more patents listed at http://www.pivotal.io/patents.
+//========================================================================
+
+using System;
+using System.Threading;
+
+namespace GemStone.GemFire.Cache.UnitTests
+{
+ using NUnit.Framework;
+ using GemStone.GemFire.DUnitFramework;
+
+ [TestFixture]
+ [Category("unicast_only")]
+ public class AckMixTests : UnitTests
+ {
+ private TallyListener m_listener = new TallyListener();
+ private AckMixRegionWrapper m_regionw;
+ private const string RegionName = "ConfusedScope";
+
+ private UnitProcess m_client1, m_client2;
+
+ protected override ClientBase[] GetClients()
+ {
+ m_client1 = new UnitProcess();
+ m_client2 = new UnitProcess();
+ return new ClientBase[] { m_client1, m_client2 };
+ }
+
+ #region Private functions
+
+ private void Init()
+ {
+ Properties dsysConfig = new Properties();
+ dsysConfig.Insert("ack-wait-threshold", "5");
+ CacheHelper.InitConfig(dsysConfig);
+ }
+
+ #endregion
+
+ #region Functions called by the tests
+
+ public void CreateRegionNOIL(int clientNum, bool ack)
+ {
+ Init();
+ string ackStr;
+ if (ack)
+ {
+ ackStr = "with-ack";
+ }
+ else
+ {
+ ackStr = "no-ack";
+ }
+ Util.Log("Creating region in client {0}, " + ackStr +
+ ", no-mirror, cache, no-interestlist, with-listener", clientNum);
+ CacheHelper.CreateILRegion(RegionName, ack, true, m_listener);
+ m_regionw = new AckMixRegionWrapper(RegionName);
+ }
+
+ //Verify no events received by the process
+ public void VerifyNoEvents()
+ {
+ Util.Log("Verifying TallyListener has received nothing.");
+ Assert.AreEqual(0, m_listener.Creates, "Should be no creates");
+ Assert.AreEqual(0, m_listener.Updates, "Should be no updates");
+ Assert.IsNull(m_listener.LastKey, "Should be no key");
+ Assert.IsNull(m_listener.LastValue, "Should be no value");
+ }
+
+ public void SendCreate()
+ {
+ Util.Log("put(1,1) from Client 1 noack");
+ m_regionw.Put(1, 1);
+ m_listener.ShowTallies();
+ }
+
+ //Test cache didn't stored update
+ public void TestCreateFromAck()
+ {
+ Util.Log("test(1, -1) in Client 2 ack");
+ m_regionw.Test(1, -1);
+
+ // now define something of our own to test create going the other way.
+ Util.Log("put(2,2) from Client 2");
+ m_regionw.Put(2, 2);
+ Assert.AreEqual(1, m_listener.Creates, "Should be 1 create.");
+ // send update from ACK to NOACK
+ Util.Log("put(1,3) from Client 2");
+
+ Thread.Sleep(10000); // see if we can drop the incoming create before we define the key.
+ m_regionw.Test(1, -1);
+
+ m_regionw.Put(1, 3);
+ Assert.AreEqual(2, m_listener.Creates, "Should be 2 creates.");
+ m_listener.ShowTallies();
+ }
+
+ public void TestCreateFromNoAck()
+ {
+ Util.Log("test( 2, -1 ) in Client 1");
+ m_regionw.Test(2, -1);
+ Util.Log("test( 1, 3 ) in Client 1");
+ m_regionw.Test(1, 3);
+
+ // Now Updates from Client 1 to Client 2.
+ Util.Log("put( 1, 5) from Client 1");
+ m_regionw.Put(1, 5);
+ m_listener.ShowTallies();
+ }
+
+ public void TestUpdateFromAck()
+ {
+ Util.Log("test( 1, 5 ) in Client 2");
+ m_regionw.Test(1, 5, true);
+ }
+
+ public void TestEventCount(int clientNum)
+ {
+ Util.Log("check Client {0} event count.", clientNum);
+ m_listener.ShowTallies();
+ Assert.AreEqual(2, m_listener.ExpectCreates(2), "Should have been 2 creates.");
+ Assert.AreEqual(1, m_listener.ExpectUpdates(1), "Should have been 1 update.");
+ }
+
+ public void TestTimeoutSetup()
+ {
+ Util.Log("creating after timeout key to verify.");
+ m_regionw.Put(40000, 1);
+ m_regionw.SetupTimeout(m_listener);
+ }
+
+ public void TestPutTimeout(int newVal)
+ {
+ Util.Log("checking that timeout works.");
+ try
+ {
+ m_listener.IgnoreTimeout = true;
+ m_regionw.RequestTimeout();
+ Assert.Fail("Should have thrown TimeoutException.");
+ }
+ catch (TimeoutException)
+ {
+ // good.. expected this... now sleep a bit and move on.
+ Util.Log("Expected: Received TimeoutException ( good news. )");
+ m_listener.IgnoreTimeout = false;
+ Thread.Sleep(10000); // other process should be clear by now.
+ m_regionw.Put(40000, newVal); // Make sure we succeed with this next put.
+ Util.Log("Sent update to key 40000.");
+ }
+ catch (Exception ex)
+ {
+ Util.Log(ex.ToString());
+ Assert.Fail(ex.Message);
+ }
+ }
+
+ public void TestAfterPutTimeout(int newVal)
+ {
+ Util.Log("verifing values made it through from TestTimeout.");
+ m_regionw.CheckTimeout();
+ m_regionw.Test(40000, newVal);
+ }
+
+ #endregion
+
+ [Test]
+ public void AckMix()
+ {
+ m_client1.Call(CreateRegionNOIL, 1, false);
+ m_client2.Call(CreateRegionNOIL, 2, true);
+
+ m_client1.Call(VerifyNoEvents);
+ m_client2.Call(VerifyNoEvents);
+
+ m_client1.Call(SendCreate);
+ m_client2.Call(TestCreateFromAck);
+
+ m_client1.Call(TestCreateFromNoAck);
+ m_client2.Call(TestUpdateFromAck);
+
+ m_client1.Call(TestEventCount, 1);
+ m_client2.Call(TestEventCount, 2);
+
+ m_client1.Call(TestTimeoutSetup);
+ m_client2.Call(TestPutTimeout, 4000);
+
+ m_client1.Call(TestAfterPutTimeout, 4000);
+ m_client2.Call(TestPutTimeout, 5000);
+
+ m_client1.Call(TestAfterPutTimeout, 5000);
+ }
+ }
+
+ class AckMixRegionWrapper : RegionWrapper
+ {
+ private bool m_timeoutUpdate;
+
+ private static CacheableString timeoutKey =
+ new CacheableString("timeout");
+
+ public AckMixRegionWrapper(string name)
+ : base(name)
+ {
+ m_timeoutUpdate = false;
+ }
+
+ public void RequestTimeout()
+ {
+ string timeoutValue = "timeout";
+ if (m_timeoutUpdate)
+ {
+ timeoutValue = "timeoutUpdate";
+ }
+ DateTime start = DateTime.Now;
+ TimeSpan span;
+ try
+ {
+ m_region.Put(timeoutKey, timeoutValue);
+ span = DateTime.Now - start;
+ Util.Log("put took {0} millis value({1})", span.TotalMilliseconds, timeoutValue);
+ }
+ catch
+ {
+ span = DateTime.Now - start;
+ Util.Log("put took {0} millis value({1})", span.TotalMilliseconds, timeoutValue);
+ m_timeoutUpdate = true;
+ throw;
+ }
+ }
+
+ public void CheckTimeout()
+ {
+ string timeoutValue = "timeout";
+ if (m_timeoutUpdate)
+ {
+ timeoutValue = "timeoutUpdate";
+ }
+ CacheableString val = m_region.Get(timeoutKey) as CacheableString;
+ Assert.AreEqual(timeoutValue, val.ToString());
+ m_timeoutUpdate = true;
+ }
+
+ public void SetupTimeout(TallyListener listener)
+ {
+ listener.IgnoreTimeout = true;
+ m_region.Put(timeoutKey, timeoutKey);
+ listener.IgnoreTimeout = false;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/integration-test/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/src/clicache/integration-test/AssemblyInfo.cs b/src/clicache/integration-test/AssemblyInfo.cs
new file mode 100644
index 0000000..327533d
--- /dev/null
+++ b/src/clicache/integration-test/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+\ufeff//=========================================================================
+// Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+// This product is protected by U.S. and international copyright
+// and intellectual property laws. Pivotal products are covered by
+// more patents listed at http://www.pivotal.io/patents.
+//========================================================================
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("UnitTests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("GEMSTONE")]
+[assembly: AssemblyProduct("UnitTests")]
+[assembly: AssemblyCopyright("Copyright � GEMSTONE 2006")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("182f654f-12a7-4355-b31c-bd54bea9eb29")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/integration-test/AttributesFactoryTestsN.cs
----------------------------------------------------------------------
diff --git a/src/clicache/integration-test/AttributesFactoryTestsN.cs b/src/clicache/integration-test/AttributesFactoryTestsN.cs
new file mode 100644
index 0000000..618a5fb
--- /dev/null
+++ b/src/clicache/integration-test/AttributesFactoryTestsN.cs
@@ -0,0 +1,98 @@
+//=========================================================================
+// Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+// This product is protected by U.S. and international copyright
+// and intellectual property laws. Pivotal products are covered by
+// more patents listed at http://www.pivotal.io/patents.
+//========================================================================
+
+//using System;
+//using System.Reflection;
+
+//#pragma warning disable 618
+
+//namespace GemStone.GemFire.Cache.UnitTests.NewAPI
+//{
+// using NUnit.Framework;
+// using GemStone.GemFire.DUnitFramework;
+// // using GemStone.GemFire.Cache;
+// using GemStone.GemFire.Cache.Generic;
+// //using Region = GemStone.GemFire.Cache.Generic.IRegion<Object, Object>;
+
+// [TestFixture]
+// [Category("group1")]
+// [Category("unicast_only")]
+// [Category("generics")]
+// public class AttributesFactoryTests : UnitTests
+// {
+// protected override ClientBase[] GetClients()
+// {
+// return null;
+// }
+
+// [Test]
+// public void InvalidTCRegionAttributes()
+// {
+// Properties<string, string> config = new Properties<string, string>();
+// CacheHelper.InitConfig(config);
+// IRegion<object, object> region;
+// RegionAttributes<object, object> attrs;
+// AttributesFactory<object, object> af = new AttributesFactory<object, object>();
+// af.SetScope(ScopeType.Local);
+// af.SetEndpoints("bass:1234");
+// attrs = af.CreateRegionAttributes();
+// region = CacheHelper.CreateRegion<object, object>("region1", attrs);
+// try
+// {
+// IRegion<Object, Object> localRegion = region.GetLocalView();
+// Assert.Fail(
+// "LOCAL scope is incompatible with a native client region");
+// }
+// catch (UnsupportedOperationException)
+// {
+// Util.Log("Got expected UnsupportedOperationException for " +
+// "LOCAL scope for native client region");
+// }
+
+// af.SetScope(ScopeType.Local);
+// af.SetClientNotificationEnabled(true);
+// attrs = af.CreateRegionAttributes();
+// try
+// {
+// region = CacheHelper.CreateRegion<object, object>("region2", attrs);
+// Assert.Fail(
+// "LOCAL scope is incompatible with clientNotificationEnabled");
+// }
+// catch (UnsupportedOperationException)
+// {
+// Util.Log("Got expected UnsupportedOperationException for " +
+// "clientNotificationEnabled for non native client region");
+// }
+
+// // Checks for HA regions
+
+// CacheHelper.CloseCache();
+// af.SetScope(ScopeType.Local);
+// af.SetEndpoints("bass:3434");
+// af.SetClientNotificationEnabled(false);
+// attrs = af.CreateRegionAttributes();
+// try
+// {
+// region = CacheHelper.CreateRegion<object, object>("region2", attrs);
+// Assert.Fail(
+// "LOCAL scope is incompatible with a native client HA region");
+// }
+// catch (UnsupportedOperationException)
+// {
+// Util.Log("Got expected UnsupportedOperationException for " +
+// "LOCAL scope for native client region");
+// }
+
+// af.SetScope(ScopeType.Local);
+// af.SetEndpoints("none");
+// af.SetClientNotificationEnabled(false);
+// attrs = af.CreateRegionAttributes();
+// region = CacheHelper.CreateRegion<object, object>("region1", attrs);
+// Util.Log("C++ local region created with HA cache specification.");
+// }
+// }
+//}
http://git-wip-us.apache.org/repos/asf/geode/blob/2d4a7ecd/src/clicache/integration-test/AttributesMutatorTestsN.cs
----------------------------------------------------------------------
diff --git a/src/clicache/integration-test/AttributesMutatorTestsN.cs b/src/clicache/integration-test/AttributesMutatorTestsN.cs
new file mode 100644
index 0000000..8de915b
--- /dev/null
+++ b/src/clicache/integration-test/AttributesMutatorTestsN.cs
@@ -0,0 +1,319 @@
+//=========================================================================
+// Copyright (c) 2002-2014 Pivotal Software, Inc. All Rights Reserved.
+// This product is protected by U.S. and international copyright
+// and intellectual property laws. Pivotal products are covered by
+// more patents listed at http://www.pivotal.io/patents.
+//========================================================================
+
+using System;
+using System.Threading;
+
+#pragma warning disable 618
+
+namespace GemStone.GemFire.Cache.UnitTests.NewAPI
+{
+ using NUnit.Framework;
+ using GemStone.GemFire.DUnitFramework;
+ using GemStone.GemFire.Cache.Generic;
+
+ using GIRegion = GemStone.GemFire.Cache.Generic.IRegion<string, string>;
+
+ class ThinClientTallyLoader : TallyLoader<string, string>
+ {
+ // Note this just returns default(TVal) hence null or empty string, use
+ // GetLoadCount() to get the load count int value.
+ public override string Load(GIRegion region, string key, object callbackArg)
+ {
+ base.Load(region, key, callbackArg);
+ int loadCount = GetLoadCount();
+ if (key != null)
+ {
+ Util.Log(Util.LogLevel.Debug,
+ "Putting the value ({0}) for local region clients only.",
+ loadCount);
+ region[key] = loadCount.ToString();
+ }
+ return loadCount.ToString();
+ }
+ }
+
+ [TestFixture]
+ [Category("group2")]
+ [Category("unicast_only")]
+ [Category("generics")]
+ public class AttributesMutatorTests : ThinClientRegionSteps
+ {
+ private UnitProcess m_client1, m_client2;
+ private const string Key = "one";
+ private const int Val = 1;
+ private const int TimeToLive = 5;
+ private const string PeerRegionName = "PEER1";
+ TallyListener<string, string> m_reg1Listener1, m_reg1Listener2;
+ TallyListener<string, string> m_reg2Listener1, m_reg2Listener2;
+ TallyListener<string, string> m_reg3Listener1, m_reg3Listener2;
+ TallyLoader<string, string> m_reg1Loader1, m_reg1Loader2;
+ TallyLoader<string, string> m_reg2Loader1, m_reg2Loader2;
+ TallyLoader<string, string> m_reg3Loader1, m_reg3Loader2;
+ TallyWriter<string, string> m_reg1Writer1, m_reg1Writer2;
+ TallyWriter<string, string> m_reg2Writer1, m_reg2Writer2;
+ TallyWriter<string, string> m_reg3Writer1, m_reg3Writer2;
+
+ protected override ClientBase[] GetClients()
+ {
+ m_client1 = new UnitProcess();
+ m_client2 = new UnitProcess();
+ return new ClientBase[] { m_client1, m_client2 };
+ }
+
+ protected override string ExtraPropertiesFile
+ {
+ get
+ {
+ return null;
+ }
+ }
+
+ #region Private methods
+
+ private void SetCacheListener(string regionName, ICacheListener<string, string> listener)
+ {
+ GIRegion region = CacheHelper.GetVerifyRegion<string, string>(regionName);
+ AttributesMutator<string, string> attrMutator = region.AttributesMutator;
+ attrMutator.SetCacheListener(listener);
+ }
+
+ private void SetCacheLoader(string regionName, ICacheLoader<string, string> loader)
+ {
+ GIRegion region = CacheHelper.GetVerifyRegion<string, string>(regionName);
+ AttributesMutator<string, string> attrMutator = region.AttributesMutator;
+ attrMutator.SetCacheLoader(loader);
+ }
+
+ private void SetCacheWriter(string regionName, ICacheWriter<string, string> writer)
+ {
+ GIRegion region = CacheHelper.GetVerifyRegion<string, string>(regionName);
+ AttributesMutator<string, string> attrMutator = region.AttributesMutator;
+ attrMutator.SetCacheWriter(writer);
+ }
+
+ private void RegisterKeys()
+ {
+ GIRegion region0 = CacheHelper.GetRegion<string, string>(m_regionNames[0]);
+ GIRegion region1 = CacheHelper.GetRegion<string, string>(m_regionNames[1]);
+ string cKey1 = m_keys[1];
+ string cKey2 = m_keys[3];
+ region0.GetSubscriptionService().RegisterKeys(new string[] { cKey1 });
+ region1.GetSubscriptionService().RegisterKeys(new string[] { cKey2 });
+ }
+
+ #endregion
+
+ #region Public methods invoked by the tests
+
+ public void StepOneCallbacks()
+ {
+ m_reg1Listener1 = new TallyListener<string, string>();
+ m_reg2Listener1 = new TallyListener<string, string>();
+ m_reg1Loader1 = new ThinClientTallyLoader();
+ m_reg2Loader1 = new ThinClientTallyLoader();
+ m_reg1Writer1 = new TallyWriter<string, string>();
+ m_reg2Writer1 = new TallyWriter<string, string>();
+
+ SetCacheListener(RegionNames[0], m_reg1Listener1);
+ SetCacheLoader(RegionNames[0], m_reg1Loader1);
+ SetCacheWriter(RegionNames[0], m_reg1Writer1);
+
+ SetCacheListener(RegionNames[1], m_reg2Listener1);
+ SetCacheLoader(RegionNames[1], m_reg2Loader1);
+ SetCacheWriter(RegionNames[1], m_reg2Writer1);
+
+ RegisterKeys();
+ m_reg3Listener1 = new TallyListener<string, string>();
+ //m_reg3Loader1 = new TallyLoader<string, string>();
+ m_reg3Loader1 = new ThinClientTallyLoader();
+ m_reg3Writer1 = new TallyWriter<string, string>();
+ AttributesFactory<string, string> af = new AttributesFactory<string, string>();
+
+ GIRegion region = CacheHelper.CreateRegion<string, string>(PeerRegionName,
+ af.CreateRegionAttributes());
+
+ SetCacheListener(PeerRegionName, m_reg3Listener1);
+ SetCacheLoader(PeerRegionName, m_reg3Loader1);
+ SetCacheWriter(PeerRegionName, m_reg3Writer1);
+
+ // Call the loader and writer
+ Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[0]),
+ "Found null value.");
+ Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[0]),
+ "Found null value.");
+ Assert.IsNotNull(GetEntry(PeerRegionName, m_keys[0]),
+ "Found null value.");
+
+ CreateEntry(PeerRegionName, m_keys[1], m_vals[1]);
+ }
+
+ public void StepTwoCallbacks()
+ {
+ AttributesFactory<string, string> af = new AttributesFactory<string, string>();
+
+ GIRegion region = CacheHelper.CreateRegion<string, string>(PeerRegionName,
+ af.CreateRegionAttributes());
+
+ CreateEntry(RegionNames[0], m_keys[1], m_vals[1]);
+ CreateEntry(RegionNames[1], m_keys[3], m_vals[3]);
+
+ SetCacheLoader(RegionNames[0], new ThinClientTallyLoader());
+ SetCacheLoader(RegionNames[1], new ThinClientTallyLoader());
+
+ Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[0]),
+ "Found null value in region0.");
+ Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[0]),
+ "Found null value in region1.");
+
+ }
+
+ public void StepThreeCallbacks()
+ {
+ Assert.AreEqual(2, m_reg1Listener1.ExpectCreates(2),
+ "Two creation events were expected for region1.");
+ Assert.AreEqual(2, m_reg2Listener1.ExpectCreates(2),
+ "Two creation events were expected for region2.");
+
+ Assert.AreEqual(0, m_reg1Listener1.ExpectUpdates(0),
+ "No update event was expected for region1.");
+ Assert.AreEqual(0, m_reg2Listener1.ExpectUpdates(0),
+ "No update event was expected for region2.");
+
+ Assert.AreEqual(1, m_reg1Loader1.ExpectLoads(1),
+ "One loader event was expected for region1.");
+ Assert.AreEqual(1, m_reg2Loader1.ExpectLoads(1),
+ "One loader event was expected for region2.");
+
+ Assert.AreEqual(1, m_reg1Writer1.ExpectCreates(1),
+ "One writer create event was expected for region1.");
+ Assert.AreEqual(1, m_reg2Writer1.ExpectCreates(1),
+ "One writer create event was expected for region2.");
+ }
+
+ public void StepFourCallbacks()
+ {
+ UpdateEntry(m_regionNames[0], m_keys[1], m_nvals[1], true);
+ UpdateEntry(m_regionNames[1], m_keys[3], m_nvals[3], true);
+ }
+
+ public void StepFiveCallbacks()
+ {
+ Assert.AreEqual(1, m_reg1Listener1.Updates,
+ "One update event was expected for region.");
+ Assert.AreEqual(1, m_reg2Listener1.Updates,
+ "One update event was expected for region.");
+
+ m_reg1Listener2 = new TallyListener<string, string>();
+ m_reg2Listener2 = new TallyListener<string, string>();
+ m_reg1Loader2 = new ThinClientTallyLoader();
+ m_reg2Loader2 = new ThinClientTallyLoader();
+ m_reg1Writer2 = new TallyWriter<string, string>();
+ m_reg2Writer2 = new TallyWriter<string, string>();
+
+ SetCacheListener(RegionNames[0], m_reg1Listener2);
+ SetCacheLoader(RegionNames[0], m_reg1Loader2);
+ SetCacheWriter(RegionNames[0], m_reg1Writer2);
+
+ SetCacheListener(RegionNames[1], m_reg2Listener2);
+ SetCacheLoader(RegionNames[1], m_reg2Loader2);
+ SetCacheWriter(RegionNames[1], m_reg2Writer2);
+
+ m_reg3Listener2 = new TallyListener<string, string>();
+ //m_reg3Loader2 = new TallyLoader<string, string>();
+ m_reg3Loader2 = new ThinClientTallyLoader();
+ m_reg3Writer2 = new TallyWriter<string, string>();
+
+ SetCacheListener(PeerRegionName, m_reg3Listener2);
+ SetCacheLoader(PeerRegionName, m_reg3Loader2);
+ SetCacheWriter(PeerRegionName, m_reg3Writer2);
+
+ // Force a fresh key get to trigger the new loaders
+ Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[2]),
+ "Found null value.");
+ Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[2]),
+ "Found null value.");
+ }
+
+
+
+ #endregion
+
+ [TearDown]
+ public override void EndTest()
+ {
+ base.EndTest();
+ }
+
+ [Test]
+ public void CreateAndVerifyExpiry()
+ {
+ try
+ {
+ IRegion<string, int> region = CacheHelper.CreateLocalRegionWithETTL<string, int>(RegionName,
+ ExpirationAction.LocalInvalidate, TimeToLive);
+
+ GemStone.GemFire.Cache.Generic.RegionAttributes<string, int> newAttrs = region.Attributes;
+ int ttl = newAttrs.EntryTimeToLive;
+ Assert.AreEqual(TimeToLive, ttl);
+
+ region[Key] = Val;
+
+ // countdown begins... it is ttl so access should not play into it..
+ Thread.Sleep(2000); // sleep for some time, expect value to still be there.
+ int res = region[Key];
+ Assert.IsNotNull(res);
+ Assert.AreEqual(Val, res);
+ Thread.Sleep(6000); // sleep for 6 more seconds, expect value to be invalid.
+ bool containsKey = region.ContainsValueForKey(Key);
+ Assert.IsFalse(containsKey, "The region should not contain the key");
+ }
+ finally
+ {
+ CacheHelper.Close();
+ }
+ }
+
+ [Test]
+ public void Callbacks()
+ {
+ CacheHelper.SetupJavaServers("cacheserver_notify_subscription.xml");
+ CacheHelper.StartJavaLocator(1, "GFELOC");
+ Util.Log("Locator 1 started.");
+ CacheHelper.StartJavaServerWithLocators(1, "GFECS1", 1);
+ Util.Log("Cacheserver 1 started.");
+
+ try
+ {
+ m_client1.Call(CreateTCRegions, RegionNames, CacheHelper.Locators, true);
+ m_client1.Call(StepOneCallbacks);
+ Util.Log("StepOne complete.");
+
+ m_client2.Call(CreateTCRegions, RegionNames, CacheHelper.Locators, true);
+ m_client2.Call(StepTwoCallbacks);
+ Util.Log("StepTwo complete.");
+
+ m_client1.Call(StepThreeCallbacks);
+ Util.Log("StepThree complete.");
+
+ m_client2.Call(StepFourCallbacks);
+ Util.Log("StepFour complete.");
+
+ m_client1.Call(StepFiveCallbacks);
+ Util.Log("StepFive complete.");
+ }
+ finally
+ {
+ CacheHelper.StopJavaServer(1);
+ Util.Log("Cacheserver 1 stopped.");
+ m_client2.Call(DestroyRegions);
+ CacheHelper.StopJavaLocator(1);
+ CacheHelper.ClearEndpoints();
+ }
+ }
+ }
+}