#!/usr/bin/env python

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

from common import *

port = start_broker("broker", "--paging-dir={0}".format(join(WORK_DIR, "pqtest_data")))

messages = 1000
address = "onepage; {create: always, node:{x-declare:{arguments:{'qpid.paging':True,'qpid.max_pages_loaded':1}}}}"

call_with_valgrind("qpid-send --messages {0} --content-size 1024 --broker localhost:{1} --address \"{2}\"",
                   messages, port, address)

output = call_for_output_with_valgrind("qpid-receive --address onepage --messages {0} --broker localhost:{1}",
                                       messages, port)

received = len(output.splitlines())

if received != messages:
    fail("Single page test failed: received {0} messages, expected {1}", received, messages)

option = "node:{x-declare:{arguments:{'qpid.paging':True,'qpid.max_size':0,'qpid.max_count':0,'qpid.flow_stop_size':0,'qpid.flow_resume_size':0,'qpid.flow_stop_count':0,'qpid.flow_resume_count':0}}}"
    
call("qpid-cpp-benchmark --broker localhost:{0} --create-option \"{1}\"", port, option)
call("qpid-cpp-benchmark --broker localhost:{0} --create-option \"{1}\" --fill-drain", port, option)

check_results()
