コード例 #1
0
void setUp(void)
{
    memset(&Session, 0, sizeof(Session));
    Session.config = (KineticSessionConfig) {
        .host = "somehost.com",
        .port = 17,
        .clusterVersion = 6,
    };
    Client.bus = &MessageBus;
    KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore);

    KineticStatus status = KineticSession_Create(&Session, &Client);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    TEST_ASSERT_FALSE(Session.connected);
    TEST_ASSERT_EQUAL_STRING(Session.config.host, "somehost.com");
    TEST_ASSERT_EQUAL(17, Session.config.port);

    KineticRequest_Init(&Request, &Session);
    OperationCompleteCallbackCount = 0;
    LastStatus = KINETIC_STATUS_INVALID;
}

void tearDown(void)
{
    KineticLogger_Close();
}

void test_KineticSession_Create_should_return_KINETIC_STATUS_SESSION_EMPTY_upon_NULL_session(void)
{
    TEST_ASSERT_EQUAL(KINETIC_STATUS_SESSION_EMPTY, KineticSession_Create(NULL, NULL));
}
コード例 #2
0
ファイル: kinetic_client.c プロジェクト: Abioy/kinetic-c
KineticStatus KineticClient_CreateSession(KineticSessionConfig* const config,
    KineticClient * const client, KineticSession** session)
{
    if (config == NULL) {
        LOG0("KineticSessionConfig is NULL!");
        return KINETIC_STATUS_SESSION_INVALID;
    }

    if (session == NULL) {
        LOG0("Pointer to KineticSession pointer is NULL!");
        return KINETIC_STATUS_SESSION_EMPTY;
    }

    if (strlen(config->host) == 0) {
        LOG0("Host is empty!");
        return KINETIC_STATUS_HOST_EMPTY;
    }

    if (config->hmacKey.len < 1 || config->hmacKey.data == NULL)
    {
        LOG0("HMAC key is NULL or empty!");
        return KINETIC_STATUS_HMAC_REQUIRED;
    }

    // Create a new session
    KineticSession* s = KineticAllocator_NewSession(client->bus, config);
    if (s == NULL) {
        LOG0("Failed to create session instance!");
        return KINETIC_STATUS_MEMORY_ERROR;
    }
    KineticStatus status = KineticSession_Create(s, client);
    if (status != KINETIC_STATUS_SUCCESS) {
        LOG0("Failed to create session instance!");
        KineticAllocator_FreeSession(s);
        return status;
    }

    // Establish the connection
    status = KineticSession_Connect(s);
    if (status != KINETIC_STATUS_SUCCESS) {
        LOGF0("Failed creating connection to %s:%d", config->host, config->port);
        KineticAllocator_FreeSession(s);
        return status;
    }

    *session = s;

    return status;
}
コード例 #3
0
void test_KineticSession_Create_should_allocate_and_destroy_KineticConnections(void)
{
    KineticSession session;
    memset(&session, 0, sizeof(session));

    KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore);

    KineticStatus status = KineticSession_Create(&session, &Client);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    TEST_ASSERT_FALSE(session.connected);
    TEST_ASSERT_EQUAL(-1, session.socket);
    TEST_ASSERT_EQUAL_INT64(0, session.sequence);
    TEST_ASSERT_EQUAL_INT64(0, session.connectionID);

    KineticCountingSemaphore_Destroy_Expect(&Semaphore);
    KineticAllocator_FreeSession_Expect(&session);

    status = KineticSession_Destroy(&session);

    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
}
コード例 #4
0
void test_KineticSession_Create_should_return_KINETIC_STATUS_SESSION_EMPTY_upon_NULL_client(void)
{
    KineticSession session;
    memset(&session, 0, sizeof(session));
    TEST_ASSERT_EQUAL(KINETIC_STATUS_SESSION_EMPTY, KineticSession_Create(&session, NULL));
}