<?xml version="1.0" encoding="utf-8"?>
<test>
<name>RT: memory vs disk kill-list</name>
<config>
searchd
{
<searchd_settings/>
	workers = threads
	binlog_path =
}

index test
{
	type	= rt
	path	= <data_path/>/testrt123
	rt_mem_limit = 128K
	rt_attr_uint = group_id
	rt_field = title
	rt_field = content
}

indexer
{
	mem_limit			= 16M
}

source dummysrc
{
	type			= mysql
	<sql_settings/>
	sql_query		= SELECT * FROM test_table where id=1
}

index dummysrcmain
{
	source			= dummysrc
	path			= <data_path/>/dummysrcmain
}

</config>

<db_create>
CREATE TABLE test_table
(
	id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
	title varchar(255) NOT NULL
);
</db_create>

<db_drop>
DROP TABLE IF EXISTS test_table;
</db_drop>

<custom_test><![CDATA[

global $g_locals, $sd_address, $sd_sphinxql_port;
$results = array();
$sockStr = "$sd_address:$sd_sphinxql_port";
if ($sd_address == "localhost")
	$sockStr = "127.0.0.1:$sd_sphinxql_port";
$sock = @mysql_connect (
	$sockStr,
	$g_locals['db-user'],
	$g_locals['db-password'] ,
	true );

if ( $sock === false )
{
	$results[] = "error: can't connect to searchd: " . @mysql_errno ( $sock ) . " : " . @mysql_error ( $sock );
	return;
}

$title = "";
$ctx = "";
for ( $i=1; $i<20; $i++ )
{
	$title .= " title$i";
	$ctx .= " ctx$i";
}

$inserted = 0;
for ( $i=1; $i<470; $i++ )
{
	$group = $i + 5000;
	$str = "INSERT INTO test ( id, group_id, title, content ) VALUES ( $i, $group, '$title', '$ctx' )";
	$res = @mysql_query ($str, $sock );
	if ($res===true)
	{
		$inserted += mysql_affected_rows($sock);
	}	
	else
	{
		$results[] = "error: insert: " . @mysql_errno ( $sock ) . " : " . @mysql_error ( $sock );
		return;
	}
}
$results[] = "total inserted=$inserted";

$queries = array ( 1, 50, 450, 469 );
for ( $i=0; $i<count ( $queries ); $i++ )
{
	$q = "select * from test where id=$queries[$i]";
	$res = @mysql_query ( $q, $sock );
	if ($res===true)
	{
		$results[] = "query $i: total_affected=" . mysql_affected_rows($sock);
	}
	else if ($res===false)
	{
		$results[] = "query $i: res=$res";
		$results[] = "error: query: " . @mysql_errno ( $sock ) . " : " . @mysql_error ( $sock );
		return;
	}
	else
	{
		$results[] = "query $i: total_rows=" . @mysql_num_rows($res);
		while ($row = @mysql_fetch_array($res, MYSQL_ASSOC))
		{
			foreach ($row as $key => $value)
				$foo[$key] = $value;
			$results[] = $foo;
		}	
	}
}

@mysql_close($sock);
	
]]></custom_test>

</test>
