# Wait for number of parts in table $1 to become $2.
# Print the changed value. If no changes for $3 seconds, prints initial value.
wait_for_number_of_parts(){
for _ in `seq $3`
do
sleep 1
res=`$CLICKHOUSE_CLIENT -q "SELECT count(*) FROM system.parts WHERE database = currentDatabase() AND table='$1' AND active"`
if["$res" -eq "$2"]
then
echo"$res"
return
fi
done
echo"$res"
}
$CLICKHOUSE_CLIENT -nmq "
DROP TABLE IF EXISTS test_without_merge;
DROP TABLE IF EXISTS test_replicated;
SELECT 'Without merge';
CREATE TABLE test_without_merge (i Int64)ENGINE= ReplicatedMergeTree('/clickhouse/tables/{database}/test02676_without_merge', 'node') ORDER BY i SETTINGS merge_selecting_sleep_ms=1000;
INSERT INTO test_without_merge SELECT 1;
INSERT INTO test_without_merge SELECT 2;
INSERT INTO test_without_merge SELECT 3;"
wait_for_number_of_parts 'test_without_merge'110
$CLICKHOUSE_CLIENT -nmq "
DROP TABLE test_without_merge;
SELECT 'With merge replicated any part range';
CREATE TABLE test_replicated (i Int64)ENGINE= ReplicatedMergeTree('/clickhouse/tables/{database}/test02676', 'node') ORDER BY i
SELECT sleepEachRow(1) FROM numbers(9) SETTINGS function_sleep_max_microseconds_per_block=10000000 FORMAT Null; -- Sleep for9 seconds and verify that we keep the old part because it's the only one