// just like the Initiator::initialize function
	void AsioSocketInitiator::initialize()
	{
		std::set < SessionID > sessions = m_settings.getSessions();
		std::set < SessionID > ::iterator i;

		if ( !sessions.size() )
			throw ConfigError( "No sessions defined" );

		SessionFactory factory( m_application, m_messageStoreFactory,
			m_pLogFactory );

		for ( i = sessions.begin(); i != sessions.end(); ++i )
		{
			if ( m_settings.get( *i ).getString( m_connection_type_label ).compare ( m_initiator_label ) == 0 )
			{
				m_sessions[ *i ] = factory.create( *i, m_settings.get( *i ) );
				ConnectSession ( *i, m_settings.get( *i ) );
			}
		}

		if ( !m_sessions.size() )
			throw ConfigError( "No sessions defined for initiator" );
	}
示例#2
0
void test_KineticClient_Init_should_initialize_the_message_bus_and_return_a_new_client(void)
{
    KineticClient client;
    KineticClientConfig config = {
        .logFile = "stdout",
        .logLevel = 3,
    };

    KineticCalloc_ExpectAndReturn(1, sizeof(KineticClient), &client);
    KineticBus_Init_ExpectAndReturn(&client, &config, true);

    KineticClient * result = KineticClient_Init(&config);

    TEST_ASSERT_EQUAL(&client, result);
}

void test_KineticClient_Init_should_return_null_if_calloc_returns_null(void)
{
    KineticClientConfig config = {
        .logFile = "stdout",
        .logLevel = 3,
    };

    KineticCalloc_ExpectAndReturn(1, sizeof(KineticClient), NULL);

    KineticClient * result = KineticClient_Init(&config);

    TEST_ASSERT_NULL(result);
}

void test_KineticClient_Init_should_free_client_if_bus_init_fails(void)
{
    KineticClient client;

    KineticClientConfig config = {
        .logFile = "stdout",
        .logLevel = 3,
    };
    KineticCalloc_ExpectAndReturn(1, sizeof(KineticClient), &client);
    KineticBus_Init_ExpectAndReturn(&client, &config, false);
    KineticFree_Expect(&client);

    KineticClient * result = KineticClient_Init(&config);
    TEST_ASSERT_NULL(result);
}

static void ConnectSession(void)
{
    KineticClient client;
    client.bus = &MessageBus;
    HmacKey = ByteArray_CreateWithCString("some hmac key");
    KineticSessionConfig config = {
        .host = "localhost",
        .port = KINETIC_PORT,
        .clusterVersion = ClusterVersion,
        .identity = Identity,
        .hmacKey = HmacKey,
    };
    Session.connected = false; // Ensure gets set appropriately by internal connect call
    Session.config = config;
    KineticSession* session;

    KineticAllocator_NewSession_ExpectAndReturn(&MessageBus, &config, &Session);
    KineticSession_Create_ExpectAndReturn(&Session, &client, KINETIC_STATUS_SUCCESS);
    KineticSession_Connect_ExpectAndReturn(&Session, KINETIC_STATUS_SUCCESS);

    KineticStatus status = KineticClient_CreateSession(&config, &client, &session);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
}


void test_KineticClient_CreateSession_should_configure_a_session_and_connect_to_specified_host(void)
{
    ConnectSession();
}

void test_KineticClient_CreateSession_should_return_KINETIC_STATUS_SESSION_EMPTY_upon_NULL_session_config(void)
{
    KineticStatus status = KineticClient_CreateSession(NULL, NULL, NULL);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SESSION_INVALID, status);
}
CassDriver::CassDriver() {
  InitLogLevelMap();
  CreateCluster();
  ConnectSession();
  PrepareQuery();
}
void test_KineticClient_Connect_should_configure_a_session_and_connect_to_specified_host(void)
{
    ConnectSession();
}