Commit be36ea44 authored by Greg Williams's avatar Greg Williams
Browse files

Updated simulator integration into example client tests to hopefully fix build

parent 0611f06d
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -86,19 +86,15 @@ makedirs:
all: clean test default run examples

clean: makedirs
	bundle exec rake clobber
	find ./bin/**/* -type f | xargs rm $1
	rm -rf ./bin/**/*.dSYM
	rm -rf ./bin/**/*.a
	rm -rf ./bin/**/*
	rm -f $(OUT_DIR)/*.o *.core *.log
	rake clobber
	git submodule update --init

.PHONY: clean makedirs
.PHONY: clean

.POSIX:

# $(OUT_DIR)/%.o: %.c $(DEPS)
# 	$(CC) -c -o $@ $< $(CFLAGS)
$(OUT_DIR)/socket99.o: $(SOCKET99)/socket99.c $(SOCKET99)/socket99.h
	$(CC) -c -o $@ $< $(CFLAGS) -I$(SOCKET99)
$(OUT_DIR)/protobuf-c.o: $(PROTOBUFC)/protobuf-c/protobuf-c.c $(PROTOBUFC)/protobuf-c/protobuf-c.h
@@ -233,14 +229,16 @@ update_simulator:

start_simulator:
	./vendor/kinetic-simulator/startSimulator.sh &
	sleep 4
	sleep 2

erase_simulator: start_simulator
	./vendor/kinetic-simulator/eraseSimulator.sh
	sleep 2
	sleep 1

stop_simulator:
	sleep 1
	./vendor/kinetic-simulator/stopSimulator.sh
	sleep 1

.PHONY: erase_simulator

@@ -319,6 +317,8 @@ $(BIN_DIR)/examples/%: $(EXAMPLE_SRC)/%.c $(KINETIC_LIB)
build_examples: $(example_executables)

run_example_%: $(BIN_DIR)/examples/%
	./vendor/kinetic-simulator/startSimulator.sh & &> /dev/null; sleep 4
	./vendor/kinetic-simulator/eraseSimulator.sh &> /dev/null; sleep 2
	@echo
	@echo ================================================================================
	@echo Executing example: '$<'
@@ -326,13 +326,14 @@ run_example_%: $(BIN_DIR)/examples/%
	$<
	@echo ================================================================================
	@echo
	@echo Stopping simulator...
	./vendor/kinetic-simulator/stopSimulator.sh &> /dev/null; sleep 2

setup_examples: $(example_executables) \
	build_examples start_simulator erase_simulator
	build_examples

examples: setup_examples \
	run_example_write_file_blocking \
	run_example_write_file_blocking_threads \
	run_example_write_file_nonblocking \
	run_example_write_file_nonblocking_threads \
	stop_simulator
+6 −6
Original line number Diff line number Diff line
@@ -161,15 +161,15 @@
			"working_dir": "${project_path}"
		},
    {
			"cmd": ["make", "all"],
      "cmd": ["make", "examples"],
      "file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
			"name": "kinetic-c - Full CI build",
      "name": "kinetic-c - Build and run Examples",
      "working_dir": "${project_path}"
    },
		{
      "cmd": ["make", "examples"],
			"cmd": ["make", "all"],
			"file_regex": "([A-Za-z][A-Za-z0-9/_]+\\.[ch])[:,] ?l?i?n?e? ?([0-9]+)[\\.:,]*([0-9]*)",
      "name": "kinetic-c - Build Examples",
			"name": "kinetic-c - Full CI build",
			"working_dir": "${project_path}"
		},
	]
+114 −1
Original line number Diff line number Diff line
@@ -28,10 +28,123 @@
#include <sys/stat.h>
#include <sys/file.h>

typedef struct {
    char ip[16];
    KineticSessionHandle sessionHandle;
    char keyPrefix[KINETIC_DEFAULT_KEY_LEN];
    uint8_t key[KINETIC_DEFAULT_KEY_LEN];
    uint8_t version[KINETIC_DEFAULT_KEY_LEN];
    uint8_t tag[KINETIC_DEFAULT_KEY_LEN];
    uint8_t value[KINETIC_OBJ_SIZE];
    KineticEntry entry;
    ByteBuffer data;
    KineticStatus status;
} write_args;

void store_data(write_args* args)
{
    KineticEntry* entry = &(args->entry);
    int32_t objIndex = 0;

    while (ByteBuffer_BytesRemaining(args->data) > 0) {

        // Configure entry meta-data
        ByteBuffer_Reset(&entry->key);
        ByteBuffer_AppendCString(&entry->key, args->keyPrefix);
        char keySuffix[8];
        snprintf(keySuffix, sizeof(keySuffix), "%02d", objIndex);
        ByteBuffer_AppendCString(&entry->key, keySuffix);

        // Prepare entry with the next object to store
        ByteBuffer_Reset(&entry->value);
        ByteBuffer_AppendArray(
            &entry->value,
            ByteBuffer_Consume(
                &args->data,
                MIN(ByteBuffer_BytesRemaining(args->data), KINETIC_OBJ_SIZE))
        );

        // Store the object
        KineticStatus status = KineticClient_Put(args->sessionHandle, entry, NULL);
        if (status != KINETIC_STATUS_SUCCESS) {
            fprintf(stderr, "Kinetic PUT of object %d to host %s failed w/ status: %s\n",
                objIndex, args->ip, Kinetic_GetStatusDescription(status));
            exit(-1);
        }

        objIndex++;
    }

    printf("File stored on Kinetic Device across %d entries\n", objIndex);
}

int main(int argc, char** argv)
{
    (void)argc;
    (void)argv;
    fprintf(stderr, "\nEXAMPLE NOT YET IMPLEMENTED!\n");

    // Read in file contents to store
    const char* dataFile = "test/support/data/test.data";
    struct stat st;
    stat(dataFile, &st);
    char* buf = malloc(st.st_size);
    int fd = open(dataFile, O_RDONLY);
    long dataLen = read(fd, buf, st.st_size);
    close(fd);
    if (dataLen <= 0) {
        fprintf(stderr, "Failed reading data file to store: %s", dataFile);
        exit(-1);
    }

    // Establish connection
    KineticStatus status;
    const char HmacKeyString[] = "asdfasdf";
    const KineticSession sessionConfig = {
        .host = "localhost",
        .port = KINETIC_PORT,
        .clusterVersion = 0,
        .identity = 1,
        .nonBlocking = false,
        .hmacKey = ByteArray_CreateWithCString(HmacKeyString),
    };
    write_args* writeArgs = calloc(1, sizeof(write_args));
    KineticClient_Init("stdout", 2);
    status = KineticClient_Connect(&sessionConfig, &writeArgs->sessionHandle);
    if (status != KINETIC_STATUS_SUCCESS) {
        fprintf(stderr, "Connection to host '%s' failed w/ status: %s",
            sessionConfig.host, Kinetic_GetStatusDescription(status));
    }

    // Create a ByteBuffer for consuming chunks of data out of for overlapped PUTs
    writeArgs->data = ByteBuffer_Create(buf, dataLen, 0);

    // Configure common meta-data for the entries
    struct timeval now;
    gettimeofday(&now, NULL);
    snprintf(writeArgs->keyPrefix, sizeof(writeArgs->keyPrefix), "%010ld_", now.tv_sec);
    ByteBuffer verBuf = ByteBuffer_Create(writeArgs->version, sizeof(writeArgs->version), 0);
    ByteBuffer_AppendCString(&verBuf, "v1.0");
    ByteBuffer tagBuf = ByteBuffer_Create(writeArgs->tag, sizeof(writeArgs->tag), 0);
    ByteBuffer_AppendCString(&tagBuf, "some_value_tag...");
    writeArgs->entry = (KineticEntry) {
        .key = ByteBuffer_Create(writeArgs->key, sizeof(writeArgs->key), 0),
        // .newVersion = verBuf,
        .tag = tagBuf,
        .algorithm = KINETIC_ALGORITHM_SHA1,
        .value = ByteBuffer_Create(writeArgs->value, sizeof(writeArgs->value), 0),
        .synchronization = KINETIC_SYNCHRONIZATION_WRITEBACK,
    };
    strcpy(writeArgs->ip, sessionConfig.host);

    // Store the data
    printf("\nWriting data file to the Kinetic device...\n");
    store_data(writeArgs);

    // Shutdown client connection and cleanup
    KineticClient_Disconnect(&writeArgs->sessionHandle);
    KineticClient_Shutdown();
    free(writeArgs);
    free(buf);

    return 0;
}