--[[----------------------------------------------------------------------------

WFRtmfpHttpClientPerformanceTest.lua

--------------------------------------------------------------------------------

ADOBE CONFIDENTIAL
------------------
Copyright 2014 Adobe Systems Incorporated
All Rights Reserved.

NOTICE: All information contained herein is, and remain the property of
Adobe Systems Incorporated and its suppliers, if any. The intellectual and
technical concepts contained herein are proprietary to Adobe Systems
Incorporated and its suppliers and may be covered by U.S. and Foreign
Patents, patents in process, and are protected by trade secret or copyright
law.  Dissemination of this information or reproduction of this material is
strictly forbidden unless prior written permission is obtained from
Adobe Systems Incorporated.

------------------------------------------------------------------------------]]

	-- WF.web.http_client
local WFHttpClient = require 'WFHttpClient'

local WFAsyncTestCase = require 'WFAsyncTestCase'
local KSPathUtils = require 'KSPathUtils'

--============================================================================--

local WFRtmfpHttpClientPerformanceTest = {}

local echoServerAddr = "http://sj1010122073213.corp.adobe.com:8124/"
local acceptServerAddr = "http://sj1010122073213.corp.adobe.com:8125/"

--------------------------------------------------------------------------------

local function doPutP( addr, putData, offset, length, dataFormat )

	return WFHttpClient.putP(
		addr,
		putData,
		{
			requestMethod = "POST",
			timeout = 300,
			offset = offset,
			length = length,
			dataFormat = dataFormat,
			requestHeaders = {
				{ header = { invalid=true }, value = "invalid key, should log but not fail", },
				{ header = "Header Has Invalid Value Will Log But Won't Fail", value = { invalid=true }, },
				{ header = "X-Unit-Test-Ignore-This", value = "ignore", },
			},
		})
		
end

----------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.DISABLEDtestRequestP_BigBinaryData_10Mb_testPerformance( test )

	-- SPAM [jandrew 2014-10-28]: Disabled since binary is too big ( 10mb ) to be
	-- a part of the lua/wf repo. Contact jandrew@adobe.com if you'd like to test this
	-- locally.

	local KSPathUtils = require 'KSPathUtils'
	local testDataPath = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testDataPath .. '/binary.txt'
	local file = io.open( filePath, 'rb' )
	
	local testData = file:read("*all")
    file:close()
			
	WFAsyncTestCase( test, 500 )
		
		:waitForPerf( function()
			return doPutP( echoServerAddr, testData )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )

end

--------------------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.testRequestP_BigData_1mb_testPerformance( test )

	local KSPathUtils = require 'KSPathUtils'
	local testDataPath = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testDataPath .. '/rtmfp/1MB.txt'
	local file = io.open( filePath, 'r' )
	
	local testData = file:read("*all")
    file:close()
			
	WFAsyncTestCase( test, 60 )
	
		:waitForPerf( function()
			return doPutP( echoServerAddr, testData )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )
end

--------------------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.testRequestP_BigData_10kb_testPerformance( test )

	local KSPathUtils = require 'KSPathUtils'
	local testDataPath = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testDataPath .. '/rtmfp/10Kb.txt'
	local file = io.open( filePath, 'r' )
	
	local testData = file:read("*all")
    file:close()
			
	WFAsyncTestCase( test, 60 )
	
		:waitForPerf( function()
			return doPutP( echoServerAddr, testData )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )

end

--------------------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.testSendP_BigData_1MB_testPerformance( test )

	local testDataFolder = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testDataFolder .. '/rtmfp/1MB.txt'
	local file = io.open( filePath, 'r' )
	local content = file:read("*all")
    file:close()

	WFAsyncTestCase( test, 200 )
	
		:waitForPerf( function()
			return doPutP( acceptServerAddr, content )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )

end

--------------------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.testSendP_BigData_10kb_testPerformance( test )

	local testData = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testData .. '/rtmfp/10Kb.txt'
	local file = io.open( filePath, 'r' )
	local content = file:read("*all")
    file:close()
	
	WFAsyncTestCase( test, 5 )
	
		:waitForPerf( function()
			return doPutP( acceptServerAddr, content )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )

end

--------------------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.DISABLEDtestSendP_BigBinaryData_10Mb_testPerformance( test )

	-- SPAM [jandrew 2014-10-28]: Disabled since binary is too big ( 10mb ) to be
	-- a part of the lua/wf repo. Contact jandrew@adobe.com if you'd like to test this
	-- locally.

	-- Message Info
	local testData = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testData .. '/binary.txt'
	local file = io.open( filePath, 'rb' )
	local content = file:read("*all")
    file:close()
	
	WFAsyncTestCase( test, 200 )
	
		:waitForPerf( function()
			return doPutP( acceptServerAddr, content )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )

end

--------------------------------------------------------------------------------

function WFRtmfpHttpClientPerformanceTest.DISABLEDtestSendP_BigBinaryData_100Mb_testPerformance( test )

	-- SPAM [jandrew 2014-10-28]: Disabled since binary_large is too big ( 100mb ) to be
	-- a part of the lua/wf repo. Contact jandrew@adobe.com if you'd like to test this
	-- locally.

	-- Message Info
	local testData = KSPathUtils.getStandardFilePath( 'testdata' )
	local filePath = testData .. '/binary_large.txt'
	local file = io.open( filePath, 'rb' )
	local content = file:read("*all")
    file:close()
	
	WFAsyncTestCase( test, 500 )
	
		:waitForPerf( function()
			return doPutP( acceptServerAddr, content )
				:mapDataP( function( status, data )
					return status, true
				end )
		end )
	
		:continueWhenValueMatches( 'data', true )

end

--------------------------------------------------------------------------------

return {}
-- return WFRtmfpHttpClientPerformanceTest
