SlideShare a Scribd company logo
1 of 47
Database API Viewed As A Mathematical Function:
Insights into Testing
Brendan Furey, March 2018
A Programmer Writes… (Brendan's Blog)
Ireland Oracle User Group, March 22-23, 2018
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 1
whoami
Freelance Oracle developer and blogger
Dublin-based Europhile
25 years Oracle experience, currently working in Finance
Started as a Fortran programmer at British Gas
Numerical analysis and optimization
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 2
Agenda
 A Design Pattern for Testing Database APIs (12 slides)
 Developing a universal design pattern for testing APIs using the concept of a ‘pure’
function as a wrapper to manage the ‘impurity’ inherent in database APIs
 A General Data Model for Testing (4 slides)
 Explaining why a general model is appropriate, and detailing the model in logical terms
and with physical array structures
 GDM Output and Code Examples (4 slides)
 Showing how test inputs and outputs can be displayed using the data model, giving some
PL/SQL code examples, and some notes on frameworks
 Test Coverage by Domain Partitioning (8 slides)
 Explaining why code coverage is not a useful testing metric and developing, from
examples, the concept of domain partitioning as a better approach for test analysis
 Testing Strategies (7 slides)
 Discussing testing strategies, including the limits of testing, why/when/what to automate,
and the homeopathic unit testing antipattern
 Conclusion (2 slides)
 Highlighting the value gained from viewing database APIs and other code from the
perspective of the mathematical function for both functional and performance testing
Brendan Furey, 2018 3Database API as Mathematical Function: Insights into Testing
A Design Pattern for Testing Database APIs
Brendan Furey, 2018 4
A Design Pattern for Testing Database APIs
Developing a universal design pattern for testing APIs using the
concept of a ‘pure’ function as a wrapper to manage the ‘impurity’
inherent in database APIs
Database API as Mathematical Function: Insights into Testing
Testing Context – Thick Database Paradigm
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 5
Guarding your data behind a hard shell PL/SQL API, OOW 2017
Why use PL/SQL?, 2015
 Manual testing
 API is called for multiple scenarios
 Calls may or may not be scripted
 Developer checks results using ad hoc queries
 Automated testing
 PL/SQL program loops over scenarios
 Checks results of API calls
 Input setup included in program
“A huge benefit of the Thick Database paradigm is that both the functional correctness and the
performance of the database module can be tested independently of any outside-of-the-database
code that will use it.” – Bryn Llewellyn
Thick Database Paradigm - Diagram
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 6
Mathematical Function
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 7
Function (mathematics) - Wikipedia
 x and y can be simple points, as shown here, or complex objects
"In mathematics, a function is a relation between a set of inputs and a set of permissible outputs with
the property that each input is related to exactly one output"
Functional Programming – Pure Functions
Functional Programming: Pure Functions
Brendan Furey, 2018 8
“A pure function is a function where the return value is only determined by its input values, without
observable side effects. This is how functions in math work: Math.cos(x) will, for the same value of x,
always return the same result. Computing it does not change x. It does not write to log files, do
network requests, ask for user input, or change program state.” - Arne Brasseur
Testing a Function
 Given a list of test inputs, X and a list of expected outputs, E, for function F:
 For each x in X, with e in E:
 Apply y = F(x)
 Assert y = e
Advantages of Purity
 Only need to check return value, y
 No coupling between tests, can be run independently in any order
 Expected return value, e, for given input, x, does not change over time, so repeatable
But Some Impurity is Necessary…
Database API as Mathematical Function: Insights into Testing
Functional Programming – Managing Impurity
Refactoring to Functional
Brendan Furey, 2018 9
“Our programs are processes that deal with inputs and generate outputs over time, they are not
mathematical functions. There are ways to get the best of both worlds, however.
One fruitful approach is to separate the pure, functional, value based core of your application from
an outer, imperative shell.” - Arne Brasseur
Database API as Mathematical Function: Insights into Testing
Database testing occurs in a noisy environment, how to manage this…
Database APIs and Impurity
Problems of Impurity for Testing
 Inputs and outputs in tables and files, as well as
parameters
 Harder to access
 One test writing to database may affect another
 Coupling increases complexity
 Nondeterministic outputs from sequences and
datetimes
 Automation hard as expected values not
knowable in advance
 Test results affected by other activity, as database
is a shared resource
 Automation hard as expected values change
over time
Brendan Furey, 2018 10
Problem of Impurity for a Chef
John Cleese in “The Dirty Fork” sketch
Database API as Mathematical Function: Insights into Testing
Database APIs – Manage Impurity by FP-Style Refactoring?
Brendan Furey, 2018 11
What Could Possibly Go Wrong?
 The pure function now becomes easier to test, and the input/output parts are small, but…
 SQL is a 4’th generation language (4GL), and its power is lost when core logic is transferred to
a 3GL layer, leading to:
 High complexity in the pure function
 Unscalability as set-based SQL gives way to array processing
Database API as Mathematical Function: Insights into Testing
Noise Cancellation
Brendan Furey, 2018 12
Noise Problem
 Developers in a European open–plan office trying to code…
 …surrounded by noisy Business Analysts and Project Managers
Solution
 Wrap our ears in Noise-
Cancelling headphones
Can we similarly cancel out the database noise when testing APIs?…
Database API as Mathematical Function: Insights into Testing
Database APIs – Manage Impurity by a Pure Wrapper
Brendan Furey, 2018 13
Wrap API in a ‘pure’ function with ‘extended signature’ and test that instead…
Database API as Mathematical Function: Insights into Testing
Test Procedure Using Pure Wrapper
Brendan Furey, 2018 14Database API as Mathematical Function: Insights into Testing
Purifying the Actuals
Non-deterministic Values
 Values such as sequence-set UIDs and SYSDATE fields non-deterministic
 Offsets from current database state and date deterministic, so apply offsets to the actuals
to purify the wrapper outputs (or, equivalently, to expected values in reverse)
 Time components may still be uncertain, but can convert these to ranges, eg an expected
update time can be assigned to a range of [test start time, test start time + 10 minutes]
 In general we may apply functions to render non-deterministic values deterministic
Filtering Out Non-Test Records
 Ideally, partition transactions by session id in a test mode as shown in next slide
 If not possible, filter out the non-test records from others, eg by using marker strings in the test
records created, then use only the test-generated records in passing the output actuals
Exceptions
 Trap exceptions raised by API and convert to text
Rollback/Undo
 Rolling back after computing actuals ensures next scenario is not coupled to the current, but…
 Autonomous transactions may need to be reversed manually (eg as in DML error logging)
Brendan Furey, 2018 15Database API as Mathematical Function: Insights into Testing
Test Mode Transaction Partitioning (if possible)
Brendan Furey, 2018 16
 Partition transactions in test mode
 Similar to eBusiness multi-org
 Tables have ttid column, access by view
 DML sets ttid to session_id in test mode
CREATE OR REPLACE VIEW employees AS
SELECT employee_id, ..., ttid
FROM hr.employees
WHERE (ttid = SYS_Context ('userenv', 'sessionid') OR
Substr (Nvl (SYS_Context ('userenv', 'client_info’),
'XX'), 1, 2) != 'TT')
Database API as Mathematical Function: Insights into Testing
A General Data Model for Testing
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 17
A General Data Model for Testing
Explaining why a general model is appropriate, and detailing the
model in logical terms and with physical array structures
A General Data Model for Testing
 Database APIs reference domain-specific data model, eg Oracle’s demo HR schema
 Data models include normalized entities, reducing redundancy and simplifying
programming
 Referential and other constraints support database integrity
 There is a natural data model for the testing of database APIs, for any domain
 Note that inputs and outputs to the wrapper API can be regarded as ‘just’ strings, or collections
of strings
 A SOAP envelope wraps inputs and outputs for a web service procedure in a generic XML
hierarchy (and JSON wraps REST service I/O)
 Similarly, we can use generic data structures for our wrapper I/O
 All that’s required outside the wrapper is to assert actual outputs against expected, and display
results in a nice format
 This can be achieved by a single call to a library utility, Is_Deeply, that takes generic PL/SQL
collections as parameters
Brendan Furey, 2018 18
This leads to a generic model for input and actual/expected output data…
Database API as Mathematical Function: Insights into Testing
A General Data Model for Testing: Data Groups
Brendan Furey, 2018 19Database API as Mathematical Function: Insights into Testing
A General Data Model for Testing: Group Metadata
Brendan Furey, 2018 20Database API as Mathematical Function: Insights into Testing
To display the results in a nice format within a general model, we can define some metadata
A General Data Model for Testing: Arrays
Brendan Furey, 2018 21
 Only 1 group level is required in general, flattening where needed
 See slide 34, ‘Complex Objects and Arrays’, for details
Database API as Mathematical Function: Insights into Testing
GDM Output and Code Examples
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 22
GDM Output and Code Examples
Extracted from my Github project, trapit_oracle_tester, showing how
test inputs and outputs can be displayed using the data model,
giving some PL/SQL code examples, and some notes on
frameworks
API Test Output Example – Showing Groups
Brendan Furey, 2018 23
SCENARIO 1: 1 valid record {
============================
INPUTS
======
GROUP Employee {
================
Name Email Job Salary
---- ----- ------- ------
LN 1 EM 1 IT_PROG 1000
}
=
OUTPUTS
=======
GROUP Employee: Actual = 1, Expected = 1 {
==========================================
F? Employee id Name Email Job Salary
-- ----------- ---- ----- ------- ------
358 LN 1 EM 1 IT_PROG 1000
} 0 failed, of 1: SUCCESS
=========================
GROUP Output array: Actual = 1, Expected = 1 {
==============================================
F? Employee id Description
-- ----------- -------------------------
358 THREE HUNDRED FIFTY-EIGHT
} 0 failed, of 1: SUCCESS
=========================
GROUP Exception: Actual = 0, Expected = 0: SUCCESS
==================================================
} 0 failed, of 3: SUCCESS
=========================
 Example shows results for first scenario of testing a
web service saving demo procedure
 Scenario tests passing 1 valid record
 1 input group, an array of employee records
 3 output groups, with #records, #failed reported
 Group: Employees table, with id, email etc.
 Group: Output array parameter, with new UID
and description
 Group: Exception raised, if any, converted to text
 # failures reported for scenario
Database API as Mathematical Function: Insights into Testing
API Test Code Extracts 1 – Array Types and Tester Main Block
Brendan Furey, 2018 24
CREATE TYPE L1_chr_arr IS VARRAY(32767) OF VARCHAR2(32767);
CREATE TYPE L2_chr_arr IS VARRAY(32767) OF L1_chr_arr;
CREATE TYPE L3_chr_arr IS VARRAY(32767) OF L2_chr_arr;
 x_lis: array of type L1_chr_arr
 x_2lis: array of type L2_chr_arr
 x_3lis: array of type L3_chr_arr
Type Definition for 1-3 Level Arrays
BEGIN
Setup_Array;
FOR i IN 1..c_params_3lis.COUNT LOOP
Purely_Wrap_API (c_params_3lis(i), l_act_3lis(i));
END LOOP;
Utils_TT.Is_Deeply (c_proc_name, c_scenario_lis, l_inp_3lis, l_act_3lis, g_exp_3lis, l_timer_set,
c_ws_ms_limit, c_inp_group_lis, c_inp_field_2lis, c_out_group_lis, c_out_field_2lis);
EXCEPTION
WHEN OTHERS THEN
Utils.Write_Other_Error; RAISE;
END tt_AIP_Save_Emps;
Typical Test Program Main Block
 All arrays passed to Is_Deeply are of one of the 3 types defined above
 Purely_Wrap_API passes variables that are 1 element in a 3-level array, for 1 scenario
 Within the procedure the parameters are defined as 2-level arrays
PROCEDURE Purely_Wrap_API (p_inp_2lis L2_chr_arr, -- input list of lists (record, field)
x_act_2lis OUT L2_chr_arr) IS -- output list of lists (group, record)
Database API as Mathematical Function: Insights into Testing
API Test Code Extracts 2 – Wrapper Main Block and Database Getter
Brendan Furey, 2018 25
BEGIN
BEGIN
Do_Save (x_emp_out_lis => l_emp_out_lis);
Get_Tab_Lis (x_tab_lis => l_tab_lis);
Get_Arr_Lis (p_emp_out_lis => l_emp_out_lis, x_arr_lis => l_arr_lis);
EXCEPTION
WHEN OTHERS THEN
l_err_lis := L1_chr_arr (SQLERRM);
END;
x_act_2lis := L2_chr_arr (Utils_TT.List_or_Empty (l_tab_lis), Utils_TT.List_or_Empty (l_arr_lis),
Utils_TT.List_or_Empty (l_err_lis));
ROLLBACK;
Typical Main Block Structure for Pure Wapper
Typical Local Procedure to Get Database Record Actuals
PROCEDURE Get_Tab_Lis (x_tab_lis OUT L1_chr_arr) IS
BEGIN
SELECT Utils.List_Delim (employee_id, last_name, email, job_id, salary)
BULK COLLECT INTO x_tab_lis
FROM employees
ORDER BY employee_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END Get_Tab_Lis;
 Exceptions trapped and converted to text
 Each group has array element in output 2lis, with empty arrays replaced by 1-record flag array
 Easy to collect delimited
actual records array
 Utility to delimit any number
of fields
 Bulk collect to output array
 No data leaves array null
Database API as Mathematical Function: Insights into Testing
 No
What frameworks can do
 Store procedures to be tested, and organize in packages and suites
 Call the test procedures using dynamic SQL
 Supply utility procedures to use in test code, such as assertions
 Supply data structures to facilitate result gathering
 Format test output results
Testing Frameworks – What to Look For
Brendan Furey, 2018 26
What frameworks can’t do
 Analysis of scenarios
 Measure completeness of scenario coverage (to be discussed)
 Write code for the database writing and reading of test records
What to look for in a testing framework
 Alignment with conceptual framework around ‘pure’ wrapper function
 Separation of assertion code from interior of wrapper function (only 1 assertion, or 1 per
scenario at most)
 Focus on features listed above with limited ‘bloat’
Database API as Mathematical Function: Insights into Testing
Test Coverage by Domain Partitioning
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 27
Test Coverage by Domain Partitioning
Explaining why code coverage is not a useful testing metric and
developing, from examples, the concept of domain partitioning as a
better approach for test analysis
Domain vs Code Coverage 1: Code Coverage
Brendan Furey, 2018 28
Why code coverage is not a reliable metric
 Simple Java example of regex email address validation
 Shows 100% code coverage for negligible scenario coverage
Base code: public bool ValidateEmail(string email)
Email address validation
 A robust email validator, with a good data-driven approach to testing
return new RegEx("[a-zA-Z0-9_]+[@][a-z]+[.]com").matches(email);
 Test code just tests 1 simple valid email address, but executes all (1 line) of base code
Test Code: void TestValidEmail()
Assert.IsTrue(EmailValidator.ValidateEmail("someone@email.com"));
“Packaged along with the free is_email() code is an XML file of 164 unit tests” – Dominic Sayers
SQL, a 4GL, can do many things in 1 statement, just like regex
 Code coverage metrics tell you almost nothing about testing quality
 Especially true for SQL and regex, but also true in general
 Focus on code metrics likely to be worse than useless, as diverting resources from other areas
We want to assess domain coverage, not code coverage…
Database API as Mathematical Function: Insights into Testing
Domain vs Code Coverage 2: Domain Coverage Example
Brendan Furey, 2018 29
 Consider bank transaction validation, inputs of account id, available credit and transaction value
 Assume return value specifies Valid or Invalid with invalidity = Id or Value
 Very large range of possible inputs, but consider the domain-partitioning scheme below
 3 regions show same return value within, but different between, regions
 In general, allow continuous variation within regions, eg return the resulting credit remaining
X Tuple Y
X1 (V1, 0) VALID
X2 (V1, -1) INV_VAL
X3 (I1, -1) INV_AID
Database API as Mathematical Function: Insights into Testing
Domain Partitioning
Brendan Furey, 2018 30
Domain-Codomain Partition Pairs
 In a mathematical function, a point X in the domain is mapped to a point Y in the codomain
 Intuitively the differing behaviours of the API function can be considered to correspond to
different pairs of domain/codomain regions within a domain partitioning scheme
 Each domain partition maps to an
image subset in codomain
 But image subsets do not form
partitions, as they may overlap
Database API as Mathematical Function: Insights into Testing
Subdomain Types and Coverage
Brendan Furey, 2018 31
Subdomain Types
 In the bank transaction example there are two types of domain (or, actually, subdomain)
 Range-Type: The amount field has behaviour defined by a numeric range, with a clear
boundary (zero here) between partitions
 2 test data points needed (just) on either side of the boundary to test both the different
behaviours and the location of the boundary
 Set-Type:The account id field has behaviour defined by whether the value is in a set or not
 2 test data points needed: 1 in the set, and 1 not in the set (or, #sets + 1 in general)
Subdomain Coverage
 If we identify p partitions in a subdomain, and have test data points in t partitions, following the
rules above, then we have:
 Subdomain Coverage Factor (SCF) = t/p x 100%
 If we have d data points covering the p partitions then we can say:
 Subdomain Coverage Efficiency (SCE) = p/d x 100%
 For multiple subdomains, we need to account for the degree of coupling between them
 In bank example, we had a subdomain of each type, but 3, not 4 (2x2), global partitions
 To see how to get global coverage figures, let’s first look at another example…
Database API as Mathematical Function: Insights into Testing
Subdomains and Decomposition
Brendan Furey, 2018 32
Independent Subdomains Example
 2 product quantity fields with prices per item banded
by quantity
 2 output prices calculated independently for each field
 Domain has 4 partitions (= 2x2)…
 …but can test in parallel, with one call testing a
partition in each subdomain, so (X1, X3) or (X2, X4)
effectively achieve full domain coverage
Coupled Subdomains Example
 Now consider the above example where 1 price per
unit is determined by both quantities, applied to both
items
 Say 4 different prices according to band-pair
 Now full coverage requires (X1, X2, X3, X4)
Graph: Pricing as Quantity Varies Across 2 Products
Database API as Mathematical Function: Insights into Testing
Global Domain Coverage
Brendan Furey, 2018 33
How many partitions in the overall domain?
 Let there be S subdomains having partitions
 Then for the global number of partitions, P, we have:
Domain Coverage
Independent Subdomains
 If all subdomains are independent we can test them in parallel
 This gives a total number of data points for full coverage as:
Fully Coupled Subdomains
 If all subdomains are interdependent we must test all partition combinations
 This gives a total number of data points for full coverage as:
Partially Coupled Subdomains
 If some, but not all, subdomains are interdependent we must evaluate which partition
combinations to test accordingly
 This gives a total number of data points for full coverage between the upper / lower limits above
Database API as Mathematical Function: Insights into Testing
Complex Objects and Arrays
Brendan Furey, 2018 34
Complex Objects as Data Points
 We think of mathematical functions as defined on a multi-dimensional space, of fixed dimension
 APIs however may take complex objects that include multi-level arrays
 We can map between the two conceptually in two steps (applied recursively):
 Consider the arrays to be of fixed size (with null elements where necessary)
 Flatten object array into fixed dimension tuple, with subdomains for each element
 Testing input/output groups apply this physically to cover all data structures in one group level
Database API as Mathematical Function: Insights into Testing
Decomposition by Arrays
Brendan Furey, 2018 35
Haskell Map Example:
“In many programming languages, map is the name of a higher-order function that applies a given
function to each element of a list, returning a list of results in the same order.”
Map (higher-order function)
> square x = x * x
> map square [1, 2, 3, 4, 5]
[1, 4, 9, 16, 25]
 Arrays are often a special case of independent subdomains
 For example, a batch load program may read independent records from a file
 In testing, the wrapper API should take an array of input records and write them to the file
 In such cases a single data point can test all subdomain partitions at once…
 …except for any global conditions, such as validation count limits
Database API as Mathematical Function: Insights into Testing
Testing Strategies
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 36
Testing Strategies
Discussing testing strategies, including the limits of testing,
why/when/what to automate, and the homeopathic unit testing
antipattern
Testing Strategy
Brendan Furey, 2018 37
Suggested Testing Strategy
 Start by analyzing the domain structure, considering:
 Partitioning
 Dependency issues
 Test efficiency and redundancy
 Follow Data Driven Testing design pattern (DDT) described earlier
 Develop the wrapper API using a single data point…
 …then further data points can be added without extra programming (except debugging)
 Aim to maintain 100% efficiency with 1 data point per partition until 100% coverage achieved
 May also be useful to preferentially test partitions according to importance or likelihood of error
Limits of Testing
 Cannot prove correctness (nor can anything else)
 ‘Pure’ wrapper function allows testing of its outputs, but what if the API writes unexpected data?
 Need to review code, not just requirements, as part of domain analysis
Database API as Mathematical Function: Insights into Testing
Phases of Testing 1: Development
Brendan Furey, 2018 38
 In the development phase test code changes repeatedly with base code
 At the end of development, base code may be safely re-factored using fixed test code
 Dependencies do not change in general over relatively short timescale
Database API as Mathematical Function: Insights into Testing
Phases of Testing 2: Regression
Brendan Furey, 2018 39
 In the regression phase test code is executed repeatedly to check dependencies
 Dependencies may change over relatively long timescale
Database API as Mathematical Function: Insights into Testing
Automated Testing: Why, When, What?
Brendan Furey, 2018 40
Why Automate?
 In manual testing we often use whatever data are present at the time
 Saves effort of creating test data, but…
 …cannot automate as inputs, and hence outputs, not known to testing program
 Automating takes significantly more effort to do initially, BUT negligible effort to repeat
When to Automate?
 Whenever repeated testing is important…
 Large projects with ongoing development over years
 Agile methodology with frequent iterations adding functionality (CI/CD)
 Ease of re-factoring desired
 Otherwise manual testing is cheaper, and a valid option
What to Automate?
 Only automate testing of the entry-point APIs, not lower level subprograms
 Within testing of an API, can mix automated and manual
 May be difficult to automate testing of some features, eg some exception handling cases
Database API as Mathematical Function: Insights into Testing
Test Only the Top-Level API, with Dependencies
Brendan Furey, 2018 41
 Diagram represents testing API code as a whole, leaving dependency intact
 This is the preferred pattern
Database API as Mathematical Function: Insights into Testing
Avoid Dependency Injection and Low-Level Tests
Brendan Furey, 2018 42
 Diagram represents mocking of dependency, and testing API code in small subprograms
 This is an antipattern approach, to be avoided, causing…
 Multiplication of test programs
 Internal interactions become integrations, no longer in scope of unit testing
 Refactoring of API no longer tested
 Breaking dependency changes no longer captured in regression testing
Database API as Mathematical Function: Insights into Testing
Homeopathic Unit Testing
Brendan Furey, 2018 43
3GL (eg Java) Unit Testing
 Test complexity often regarded as a ‘code smell’
 Aim to test code in small chunks and in isolation
 Mock any dependencies
Database Testing
 Database API in PL/SQL embedding SQL
 Aim to do ‘heavy lifting’ in SQL, which is a 4GL
 Breaking into small chunks the ‘code smell’ here
 Want to test dependencies continue to be
consistent in regression phase
Homeopathic Unit Testing
 …testing small code sections without
dependencies or significant structure
 Regression tests are to test re-factoring and
dependency changes
Database API as Mathematical Function: Insights into Testing
Conclusion
Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 44
Conclusion
Highlighting the value gained from viewing database APIs and other
code from the perspective of the mathematical function for both
functional and performance testing
Value of the Mathematical Function in Functional Testing
Brendan Furey, 2018 45
 Universal design pattern via ‘pure’ wrapper function around API
 Provides standard template for programs
 Resolves ‘brittleness’ caused by database impurity issues
 Wrapper parameters may be seen as the ‘extended signature’ of the API
 General 3-level data model for function inputs and outputs, expected and actual
 Centralizes assertion in one library call, simplifying code
 Data driven testing results in cleaner code and better testing
 Test analysis and coverage benefit from domain partitioning approach
Database API as Mathematical Function: Insights into Testing
Value of the Mathematical Function in Performance Testing
Brendan Furey, 2018 46
Dimensional Performance Benchmarking of SQL - IOUG Presentation, 2017
 Consider the resource usage of a query (or any code) to vary as a function of problem size
 As with functional testing, set up and clear the test data programmatically
 Call the function under test in a loop over a range of sizing dimension values
 Sizing dimension can be anything that affects performance, such as number of records
 Performance measure can be elapsed or CPU time, or any Oracle-instrumented measure
 Gives useful information about comparative performance and scalability of different methods
 Frameworks for automated testing, both functional and performance, available here:
Brendan’s GitHub Page
 Performance variation can often be
expressed as a function of sizing dimension
 Sampling across a range allows us to
estimate the form of the function
Database API as Mathematical Function: Insights into Testing
References
1. A Programmer Writes… (Brendan's Blog)
2. Guarding your data behind a hard shell PL/SQL API, OOW 2017
3. Why use PL/SQL?, 2015
4. Function (mathematics) - Wikipedia
5. Functional Programming: Pure Functions
6. GitHub: trapit_oracle_tester
7. Why code coverage is not a reliable metric
8. Email address validation
9. Map (higher-order function)
10. Dimensional Performance Benchmarking of SQL - IOUG Presentation, 2017
Brendan Furey, 2018 47Database API as Mathematical Function: Insights into Testing

More Related Content

What's hot

Password protected diary
Password protected diaryPassword protected diary
Password protected diarySHARDA SHARAN
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservicesMohammed Shaban
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaperoracle documents
 
An ai planning approach for generating
An ai planning approach for generatingAn ai planning approach for generating
An ai planning approach for generatingijaia
 
The Database Environment Chapter 8
The Database Environment Chapter 8The Database Environment Chapter 8
The Database Environment Chapter 8Jeanie Arnoco
 
Oracle RI ETL process overview.
Oracle RI ETL process overview.Oracle RI ETL process overview.
Oracle RI ETL process overview.Puneet Kala
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer OverviewOlav Sandstå
 
Couplingand cohesion student
Couplingand cohesion studentCouplingand cohesion student
Couplingand cohesion studentsaurabh kumar
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer OverviewMYXPLAIN
 
Determan SummerSim_submit_rev3
Determan SummerSim_submit_rev3Determan SummerSim_submit_rev3
Determan SummerSim_submit_rev3John Determan
 
Ty bca-sem-v-introduction to vb.net-i-uploaded
Ty bca-sem-v-introduction to vb.net-i-uploadedTy bca-sem-v-introduction to vb.net-i-uploaded
Ty bca-sem-v-introduction to vb.net-i-uploadedPrachi Sasankar
 
Apache Cassandra - Drivers deep dive
Apache Cassandra - Drivers deep diveApache Cassandra - Drivers deep dive
Apache Cassandra - Drivers deep diveAlex Thompson
 
12 couplingand cohesion-student
12 couplingand cohesion-student12 couplingand cohesion-student
12 couplingand cohesion-studentrandhirlpu
 
A Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution TechniquesA Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution TechniquesSung Kim
 

What's hot (20)

Password protected diary
Password protected diaryPassword protected diary
Password protected diary
 
GraphQL API Gateway and microservices
GraphQL API Gateway and microservicesGraphQL API Gateway and microservices
GraphQL API Gateway and microservices
 
Sql scripting sorcerypaper
Sql scripting sorcerypaperSql scripting sorcerypaper
Sql scripting sorcerypaper
 
An ai planning approach for generating
An ai planning approach for generatingAn ai planning approach for generating
An ai planning approach for generating
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
Vedic Calculator
Vedic CalculatorVedic Calculator
Vedic Calculator
 
The Database Environment Chapter 8
The Database Environment Chapter 8The Database Environment Chapter 8
The Database Environment Chapter 8
 
ch4
ch4ch4
ch4
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Oracle RI ETL process overview.
Oracle RI ETL process overview.Oracle RI ETL process overview.
Oracle RI ETL process overview.
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Couplingand cohesion student
Couplingand cohesion studentCouplingand cohesion student
Couplingand cohesion student
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Determan SummerSim_submit_rev3
Determan SummerSim_submit_rev3Determan SummerSim_submit_rev3
Determan SummerSim_submit_rev3
 
Ty bca-sem-v-introduction to vb.net-i-uploaded
Ty bca-sem-v-introduction to vb.net-i-uploadedTy bca-sem-v-introduction to vb.net-i-uploaded
Ty bca-sem-v-introduction to vb.net-i-uploaded
 
Apache Cassandra - Drivers deep dive
Apache Cassandra - Drivers deep diveApache Cassandra - Drivers deep dive
Apache Cassandra - Drivers deep dive
 
12 couplingand cohesion-student
12 couplingand cohesion-student12 couplingand cohesion-student
12 couplingand cohesion-student
 
Naiditch resume may02
Naiditch resume may02Naiditch resume may02
Naiditch resume may02
 
C24011018
C24011018C24011018
C24011018
 
A Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution TechniquesA Survey on Automatic Software Evolution Techniques
A Survey on Automatic Software Evolution Techniques
 

Similar to Database API Viewed as a Mathematical Function, Insights into Testing

Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Rusif Eyvazli
 
Comparing the performance of a business process: using Excel & Python
Comparing the performance of a business process: using Excel & PythonComparing the performance of a business process: using Excel & Python
Comparing the performance of a business process: using Excel & PythonIRJET Journal
 
Boost your App with Gatling
Boost your App with GatlingBoost your App with Gatling
Boost your App with GatlingKnoldus Inc.
 
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019VMware Tanzu
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testingb4usolution .
 
EPAM ML/AI Accelerator - ODAHU
EPAM ML/AI Accelerator - ODAHUEPAM ML/AI Accelerator - ODAHU
EPAM ML/AI Accelerator - ODAHUDmitrii Suslov
 
So Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test BlackboardSo Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test BlackboardSteve Feldman
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicDavid Solivan
 
Bt0066 database management system2
Bt0066 database management system2Bt0066 database management system2
Bt0066 database management system2Techglyphs
 
Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 EstimationLawrence Bernstein
 
Application Parameter Description Scheme For Multiple Job Generation In Probl...
Application Parameter Description Scheme For Multiple Job Generation In Probl...Application Parameter Description Scheme For Multiple Job Generation In Probl...
Application Parameter Description Scheme For Multiple Job Generation In Probl...James Heller
 
Clean coding in plsql and sql, v2
Clean coding in plsql and sql, v2Clean coding in plsql and sql, v2
Clean coding in plsql and sql, v2Brendan Furey
 
Applying linear regression and predictive analytics
Applying linear regression and predictive analyticsApplying linear regression and predictive analytics
Applying linear regression and predictive analyticsMariaDB plc
 
Estimation and planning with smart use cases
Estimation and planning with smart use casesEstimation and planning with smart use cases
Estimation and planning with smart use casesRobert de Wolff
 

Similar to Database API Viewed as a Mathematical Function, Insights into Testing (20)

Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...Scaling Application on High Performance Computing Clusters and Analysis of th...
Scaling Application on High Performance Computing Clusters and Analysis of th...
 
Comparing the performance of a business process: using Excel & Python
Comparing the performance of a business process: using Excel & PythonComparing the performance of a business process: using Excel & Python
Comparing the performance of a business process: using Excel & Python
 
Boost your App with Gatling
Boost your App with GatlingBoost your App with Gatling
Boost your App with Gatling
 
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
Agile Data Science on Greenplum Using Airflow - Greenplum Summit 2019
 
Ch15-22-23 (1).ppt
Ch15-22-23 (1).pptCh15-22-23 (1).ppt
Ch15-22-23 (1).ppt
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testing
 
EPAM ML/AI Accelerator - ODAHU
EPAM ML/AI Accelerator - ODAHUEPAM ML/AI Accelerator - ODAHU
EPAM ML/AI Accelerator - ODAHU
 
Ijetr011834
Ijetr011834Ijetr011834
Ijetr011834
 
final
finalfinal
final
 
So Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test BlackboardSo Your Boss Wants You to Performance Test Blackboard
So Your Boss Wants You to Performance Test Blackboard
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs Public
 
Benchmarking PyCon AU 2011 v0
Benchmarking PyCon AU 2011 v0Benchmarking PyCon AU 2011 v0
Benchmarking PyCon AU 2011 v0
 
Bt0066 database management system2
Bt0066 database management system2Bt0066 database management system2
Bt0066 database management system2
 
Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 Estimation
 
Application Parameter Description Scheme For Multiple Job Generation In Probl...
Application Parameter Description Scheme For Multiple Job Generation In Probl...Application Parameter Description Scheme For Multiple Job Generation In Probl...
Application Parameter Description Scheme For Multiple Job Generation In Probl...
 
Clean coding in plsql and sql, v2
Clean coding in plsql and sql, v2Clean coding in plsql and sql, v2
Clean coding in plsql and sql, v2
 
Test automation process
Test automation processTest automation process
Test automation process
 
Test automation process _ QTP
Test automation process _ QTPTest automation process _ QTP
Test automation process _ QTP
 
Applying linear regression and predictive analytics
Applying linear regression and predictive analyticsApplying linear regression and predictive analytics
Applying linear regression and predictive analytics
 
Estimation and planning with smart use cases
Estimation and planning with smart use casesEstimation and planning with smart use cases
Estimation and planning with smart use cases
 

Recently uploaded

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Recently uploaded (20)

Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

Database API Viewed as a Mathematical Function, Insights into Testing

  • 1. Database API Viewed As A Mathematical Function: Insights into Testing Brendan Furey, March 2018 A Programmer Writes… (Brendan's Blog) Ireland Oracle User Group, March 22-23, 2018 Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 1
  • 2. whoami Freelance Oracle developer and blogger Dublin-based Europhile 25 years Oracle experience, currently working in Finance Started as a Fortran programmer at British Gas Numerical analysis and optimization Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 2
  • 3. Agenda  A Design Pattern for Testing Database APIs (12 slides)  Developing a universal design pattern for testing APIs using the concept of a ‘pure’ function as a wrapper to manage the ‘impurity’ inherent in database APIs  A General Data Model for Testing (4 slides)  Explaining why a general model is appropriate, and detailing the model in logical terms and with physical array structures  GDM Output and Code Examples (4 slides)  Showing how test inputs and outputs can be displayed using the data model, giving some PL/SQL code examples, and some notes on frameworks  Test Coverage by Domain Partitioning (8 slides)  Explaining why code coverage is not a useful testing metric and developing, from examples, the concept of domain partitioning as a better approach for test analysis  Testing Strategies (7 slides)  Discussing testing strategies, including the limits of testing, why/when/what to automate, and the homeopathic unit testing antipattern  Conclusion (2 slides)  Highlighting the value gained from viewing database APIs and other code from the perspective of the mathematical function for both functional and performance testing Brendan Furey, 2018 3Database API as Mathematical Function: Insights into Testing
  • 4. A Design Pattern for Testing Database APIs Brendan Furey, 2018 4 A Design Pattern for Testing Database APIs Developing a universal design pattern for testing APIs using the concept of a ‘pure’ function as a wrapper to manage the ‘impurity’ inherent in database APIs Database API as Mathematical Function: Insights into Testing
  • 5. Testing Context – Thick Database Paradigm Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 5 Guarding your data behind a hard shell PL/SQL API, OOW 2017 Why use PL/SQL?, 2015  Manual testing  API is called for multiple scenarios  Calls may or may not be scripted  Developer checks results using ad hoc queries  Automated testing  PL/SQL program loops over scenarios  Checks results of API calls  Input setup included in program “A huge benefit of the Thick Database paradigm is that both the functional correctness and the performance of the database module can be tested independently of any outside-of-the-database code that will use it.” – Bryn Llewellyn
  • 6. Thick Database Paradigm - Diagram Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 6
  • 7. Mathematical Function Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 7 Function (mathematics) - Wikipedia  x and y can be simple points, as shown here, or complex objects "In mathematics, a function is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output"
  • 8. Functional Programming – Pure Functions Functional Programming: Pure Functions Brendan Furey, 2018 8 “A pure function is a function where the return value is only determined by its input values, without observable side effects. This is how functions in math work: Math.cos(x) will, for the same value of x, always return the same result. Computing it does not change x. It does not write to log files, do network requests, ask for user input, or change program state.” - Arne Brasseur Testing a Function  Given a list of test inputs, X and a list of expected outputs, E, for function F:  For each x in X, with e in E:  Apply y = F(x)  Assert y = e Advantages of Purity  Only need to check return value, y  No coupling between tests, can be run independently in any order  Expected return value, e, for given input, x, does not change over time, so repeatable But Some Impurity is Necessary… Database API as Mathematical Function: Insights into Testing
  • 9. Functional Programming – Managing Impurity Refactoring to Functional Brendan Furey, 2018 9 “Our programs are processes that deal with inputs and generate outputs over time, they are not mathematical functions. There are ways to get the best of both worlds, however. One fruitful approach is to separate the pure, functional, value based core of your application from an outer, imperative shell.” - Arne Brasseur Database API as Mathematical Function: Insights into Testing
  • 10. Database testing occurs in a noisy environment, how to manage this… Database APIs and Impurity Problems of Impurity for Testing  Inputs and outputs in tables and files, as well as parameters  Harder to access  One test writing to database may affect another  Coupling increases complexity  Nondeterministic outputs from sequences and datetimes  Automation hard as expected values not knowable in advance  Test results affected by other activity, as database is a shared resource  Automation hard as expected values change over time Brendan Furey, 2018 10 Problem of Impurity for a Chef John Cleese in “The Dirty Fork” sketch Database API as Mathematical Function: Insights into Testing
  • 11. Database APIs – Manage Impurity by FP-Style Refactoring? Brendan Furey, 2018 11 What Could Possibly Go Wrong?  The pure function now becomes easier to test, and the input/output parts are small, but…  SQL is a 4’th generation language (4GL), and its power is lost when core logic is transferred to a 3GL layer, leading to:  High complexity in the pure function  Unscalability as set-based SQL gives way to array processing Database API as Mathematical Function: Insights into Testing
  • 12. Noise Cancellation Brendan Furey, 2018 12 Noise Problem  Developers in a European open–plan office trying to code…  …surrounded by noisy Business Analysts and Project Managers Solution  Wrap our ears in Noise- Cancelling headphones Can we similarly cancel out the database noise when testing APIs?… Database API as Mathematical Function: Insights into Testing
  • 13. Database APIs – Manage Impurity by a Pure Wrapper Brendan Furey, 2018 13 Wrap API in a ‘pure’ function with ‘extended signature’ and test that instead… Database API as Mathematical Function: Insights into Testing
  • 14. Test Procedure Using Pure Wrapper Brendan Furey, 2018 14Database API as Mathematical Function: Insights into Testing
  • 15. Purifying the Actuals Non-deterministic Values  Values such as sequence-set UIDs and SYSDATE fields non-deterministic  Offsets from current database state and date deterministic, so apply offsets to the actuals to purify the wrapper outputs (or, equivalently, to expected values in reverse)  Time components may still be uncertain, but can convert these to ranges, eg an expected update time can be assigned to a range of [test start time, test start time + 10 minutes]  In general we may apply functions to render non-deterministic values deterministic Filtering Out Non-Test Records  Ideally, partition transactions by session id in a test mode as shown in next slide  If not possible, filter out the non-test records from others, eg by using marker strings in the test records created, then use only the test-generated records in passing the output actuals Exceptions  Trap exceptions raised by API and convert to text Rollback/Undo  Rolling back after computing actuals ensures next scenario is not coupled to the current, but…  Autonomous transactions may need to be reversed manually (eg as in DML error logging) Brendan Furey, 2018 15Database API as Mathematical Function: Insights into Testing
  • 16. Test Mode Transaction Partitioning (if possible) Brendan Furey, 2018 16  Partition transactions in test mode  Similar to eBusiness multi-org  Tables have ttid column, access by view  DML sets ttid to session_id in test mode CREATE OR REPLACE VIEW employees AS SELECT employee_id, ..., ttid FROM hr.employees WHERE (ttid = SYS_Context ('userenv', 'sessionid') OR Substr (Nvl (SYS_Context ('userenv', 'client_info’), 'XX'), 1, 2) != 'TT') Database API as Mathematical Function: Insights into Testing
  • 17. A General Data Model for Testing Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 17 A General Data Model for Testing Explaining why a general model is appropriate, and detailing the model in logical terms and with physical array structures
  • 18. A General Data Model for Testing  Database APIs reference domain-specific data model, eg Oracle’s demo HR schema  Data models include normalized entities, reducing redundancy and simplifying programming  Referential and other constraints support database integrity  There is a natural data model for the testing of database APIs, for any domain  Note that inputs and outputs to the wrapper API can be regarded as ‘just’ strings, or collections of strings  A SOAP envelope wraps inputs and outputs for a web service procedure in a generic XML hierarchy (and JSON wraps REST service I/O)  Similarly, we can use generic data structures for our wrapper I/O  All that’s required outside the wrapper is to assert actual outputs against expected, and display results in a nice format  This can be achieved by a single call to a library utility, Is_Deeply, that takes generic PL/SQL collections as parameters Brendan Furey, 2018 18 This leads to a generic model for input and actual/expected output data… Database API as Mathematical Function: Insights into Testing
  • 19. A General Data Model for Testing: Data Groups Brendan Furey, 2018 19Database API as Mathematical Function: Insights into Testing
  • 20. A General Data Model for Testing: Group Metadata Brendan Furey, 2018 20Database API as Mathematical Function: Insights into Testing To display the results in a nice format within a general model, we can define some metadata
  • 21. A General Data Model for Testing: Arrays Brendan Furey, 2018 21  Only 1 group level is required in general, flattening where needed  See slide 34, ‘Complex Objects and Arrays’, for details Database API as Mathematical Function: Insights into Testing
  • 22. GDM Output and Code Examples Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 22 GDM Output and Code Examples Extracted from my Github project, trapit_oracle_tester, showing how test inputs and outputs can be displayed using the data model, giving some PL/SQL code examples, and some notes on frameworks
  • 23. API Test Output Example – Showing Groups Brendan Furey, 2018 23 SCENARIO 1: 1 valid record { ============================ INPUTS ====== GROUP Employee { ================ Name Email Job Salary ---- ----- ------- ------ LN 1 EM 1 IT_PROG 1000 } = OUTPUTS ======= GROUP Employee: Actual = 1, Expected = 1 { ========================================== F? Employee id Name Email Job Salary -- ----------- ---- ----- ------- ------ 358 LN 1 EM 1 IT_PROG 1000 } 0 failed, of 1: SUCCESS ========================= GROUP Output array: Actual = 1, Expected = 1 { ============================================== F? Employee id Description -- ----------- ------------------------- 358 THREE HUNDRED FIFTY-EIGHT } 0 failed, of 1: SUCCESS ========================= GROUP Exception: Actual = 0, Expected = 0: SUCCESS ================================================== } 0 failed, of 3: SUCCESS =========================  Example shows results for first scenario of testing a web service saving demo procedure  Scenario tests passing 1 valid record  1 input group, an array of employee records  3 output groups, with #records, #failed reported  Group: Employees table, with id, email etc.  Group: Output array parameter, with new UID and description  Group: Exception raised, if any, converted to text  # failures reported for scenario Database API as Mathematical Function: Insights into Testing
  • 24. API Test Code Extracts 1 – Array Types and Tester Main Block Brendan Furey, 2018 24 CREATE TYPE L1_chr_arr IS VARRAY(32767) OF VARCHAR2(32767); CREATE TYPE L2_chr_arr IS VARRAY(32767) OF L1_chr_arr; CREATE TYPE L3_chr_arr IS VARRAY(32767) OF L2_chr_arr;  x_lis: array of type L1_chr_arr  x_2lis: array of type L2_chr_arr  x_3lis: array of type L3_chr_arr Type Definition for 1-3 Level Arrays BEGIN Setup_Array; FOR i IN 1..c_params_3lis.COUNT LOOP Purely_Wrap_API (c_params_3lis(i), l_act_3lis(i)); END LOOP; Utils_TT.Is_Deeply (c_proc_name, c_scenario_lis, l_inp_3lis, l_act_3lis, g_exp_3lis, l_timer_set, c_ws_ms_limit, c_inp_group_lis, c_inp_field_2lis, c_out_group_lis, c_out_field_2lis); EXCEPTION WHEN OTHERS THEN Utils.Write_Other_Error; RAISE; END tt_AIP_Save_Emps; Typical Test Program Main Block  All arrays passed to Is_Deeply are of one of the 3 types defined above  Purely_Wrap_API passes variables that are 1 element in a 3-level array, for 1 scenario  Within the procedure the parameters are defined as 2-level arrays PROCEDURE Purely_Wrap_API (p_inp_2lis L2_chr_arr, -- input list of lists (record, field) x_act_2lis OUT L2_chr_arr) IS -- output list of lists (group, record) Database API as Mathematical Function: Insights into Testing
  • 25. API Test Code Extracts 2 – Wrapper Main Block and Database Getter Brendan Furey, 2018 25 BEGIN BEGIN Do_Save (x_emp_out_lis => l_emp_out_lis); Get_Tab_Lis (x_tab_lis => l_tab_lis); Get_Arr_Lis (p_emp_out_lis => l_emp_out_lis, x_arr_lis => l_arr_lis); EXCEPTION WHEN OTHERS THEN l_err_lis := L1_chr_arr (SQLERRM); END; x_act_2lis := L2_chr_arr (Utils_TT.List_or_Empty (l_tab_lis), Utils_TT.List_or_Empty (l_arr_lis), Utils_TT.List_or_Empty (l_err_lis)); ROLLBACK; Typical Main Block Structure for Pure Wapper Typical Local Procedure to Get Database Record Actuals PROCEDURE Get_Tab_Lis (x_tab_lis OUT L1_chr_arr) IS BEGIN SELECT Utils.List_Delim (employee_id, last_name, email, job_id, salary) BULK COLLECT INTO x_tab_lis FROM employees ORDER BY employee_id; EXCEPTION WHEN NO_DATA_FOUND THEN NULL; END Get_Tab_Lis;  Exceptions trapped and converted to text  Each group has array element in output 2lis, with empty arrays replaced by 1-record flag array  Easy to collect delimited actual records array  Utility to delimit any number of fields  Bulk collect to output array  No data leaves array null Database API as Mathematical Function: Insights into Testing
  • 26.  No What frameworks can do  Store procedures to be tested, and organize in packages and suites  Call the test procedures using dynamic SQL  Supply utility procedures to use in test code, such as assertions  Supply data structures to facilitate result gathering  Format test output results Testing Frameworks – What to Look For Brendan Furey, 2018 26 What frameworks can’t do  Analysis of scenarios  Measure completeness of scenario coverage (to be discussed)  Write code for the database writing and reading of test records What to look for in a testing framework  Alignment with conceptual framework around ‘pure’ wrapper function  Separation of assertion code from interior of wrapper function (only 1 assertion, or 1 per scenario at most)  Focus on features listed above with limited ‘bloat’ Database API as Mathematical Function: Insights into Testing
  • 27. Test Coverage by Domain Partitioning Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 27 Test Coverage by Domain Partitioning Explaining why code coverage is not a useful testing metric and developing, from examples, the concept of domain partitioning as a better approach for test analysis
  • 28. Domain vs Code Coverage 1: Code Coverage Brendan Furey, 2018 28 Why code coverage is not a reliable metric  Simple Java example of regex email address validation  Shows 100% code coverage for negligible scenario coverage Base code: public bool ValidateEmail(string email) Email address validation  A robust email validator, with a good data-driven approach to testing return new RegEx("[a-zA-Z0-9_]+[@][a-z]+[.]com").matches(email);  Test code just tests 1 simple valid email address, but executes all (1 line) of base code Test Code: void TestValidEmail() Assert.IsTrue(EmailValidator.ValidateEmail("someone@email.com")); “Packaged along with the free is_email() code is an XML file of 164 unit tests” – Dominic Sayers SQL, a 4GL, can do many things in 1 statement, just like regex  Code coverage metrics tell you almost nothing about testing quality  Especially true for SQL and regex, but also true in general  Focus on code metrics likely to be worse than useless, as diverting resources from other areas We want to assess domain coverage, not code coverage… Database API as Mathematical Function: Insights into Testing
  • 29. Domain vs Code Coverage 2: Domain Coverage Example Brendan Furey, 2018 29  Consider bank transaction validation, inputs of account id, available credit and transaction value  Assume return value specifies Valid or Invalid with invalidity = Id or Value  Very large range of possible inputs, but consider the domain-partitioning scheme below  3 regions show same return value within, but different between, regions  In general, allow continuous variation within regions, eg return the resulting credit remaining X Tuple Y X1 (V1, 0) VALID X2 (V1, -1) INV_VAL X3 (I1, -1) INV_AID Database API as Mathematical Function: Insights into Testing
  • 30. Domain Partitioning Brendan Furey, 2018 30 Domain-Codomain Partition Pairs  In a mathematical function, a point X in the domain is mapped to a point Y in the codomain  Intuitively the differing behaviours of the API function can be considered to correspond to different pairs of domain/codomain regions within a domain partitioning scheme  Each domain partition maps to an image subset in codomain  But image subsets do not form partitions, as they may overlap Database API as Mathematical Function: Insights into Testing
  • 31. Subdomain Types and Coverage Brendan Furey, 2018 31 Subdomain Types  In the bank transaction example there are two types of domain (or, actually, subdomain)  Range-Type: The amount field has behaviour defined by a numeric range, with a clear boundary (zero here) between partitions  2 test data points needed (just) on either side of the boundary to test both the different behaviours and the location of the boundary  Set-Type:The account id field has behaviour defined by whether the value is in a set or not  2 test data points needed: 1 in the set, and 1 not in the set (or, #sets + 1 in general) Subdomain Coverage  If we identify p partitions in a subdomain, and have test data points in t partitions, following the rules above, then we have:  Subdomain Coverage Factor (SCF) = t/p x 100%  If we have d data points covering the p partitions then we can say:  Subdomain Coverage Efficiency (SCE) = p/d x 100%  For multiple subdomains, we need to account for the degree of coupling between them  In bank example, we had a subdomain of each type, but 3, not 4 (2x2), global partitions  To see how to get global coverage figures, let’s first look at another example… Database API as Mathematical Function: Insights into Testing
  • 32. Subdomains and Decomposition Brendan Furey, 2018 32 Independent Subdomains Example  2 product quantity fields with prices per item banded by quantity  2 output prices calculated independently for each field  Domain has 4 partitions (= 2x2)…  …but can test in parallel, with one call testing a partition in each subdomain, so (X1, X3) or (X2, X4) effectively achieve full domain coverage Coupled Subdomains Example  Now consider the above example where 1 price per unit is determined by both quantities, applied to both items  Say 4 different prices according to band-pair  Now full coverage requires (X1, X2, X3, X4) Graph: Pricing as Quantity Varies Across 2 Products Database API as Mathematical Function: Insights into Testing
  • 33. Global Domain Coverage Brendan Furey, 2018 33 How many partitions in the overall domain?  Let there be S subdomains having partitions  Then for the global number of partitions, P, we have: Domain Coverage Independent Subdomains  If all subdomains are independent we can test them in parallel  This gives a total number of data points for full coverage as: Fully Coupled Subdomains  If all subdomains are interdependent we must test all partition combinations  This gives a total number of data points for full coverage as: Partially Coupled Subdomains  If some, but not all, subdomains are interdependent we must evaluate which partition combinations to test accordingly  This gives a total number of data points for full coverage between the upper / lower limits above Database API as Mathematical Function: Insights into Testing
  • 34. Complex Objects and Arrays Brendan Furey, 2018 34 Complex Objects as Data Points  We think of mathematical functions as defined on a multi-dimensional space, of fixed dimension  APIs however may take complex objects that include multi-level arrays  We can map between the two conceptually in two steps (applied recursively):  Consider the arrays to be of fixed size (with null elements where necessary)  Flatten object array into fixed dimension tuple, with subdomains for each element  Testing input/output groups apply this physically to cover all data structures in one group level Database API as Mathematical Function: Insights into Testing
  • 35. Decomposition by Arrays Brendan Furey, 2018 35 Haskell Map Example: “In many programming languages, map is the name of a higher-order function that applies a given function to each element of a list, returning a list of results in the same order.” Map (higher-order function) > square x = x * x > map square [1, 2, 3, 4, 5] [1, 4, 9, 16, 25]  Arrays are often a special case of independent subdomains  For example, a batch load program may read independent records from a file  In testing, the wrapper API should take an array of input records and write them to the file  In such cases a single data point can test all subdomain partitions at once…  …except for any global conditions, such as validation count limits Database API as Mathematical Function: Insights into Testing
  • 36. Testing Strategies Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 36 Testing Strategies Discussing testing strategies, including the limits of testing, why/when/what to automate, and the homeopathic unit testing antipattern
  • 37. Testing Strategy Brendan Furey, 2018 37 Suggested Testing Strategy  Start by analyzing the domain structure, considering:  Partitioning  Dependency issues  Test efficiency and redundancy  Follow Data Driven Testing design pattern (DDT) described earlier  Develop the wrapper API using a single data point…  …then further data points can be added without extra programming (except debugging)  Aim to maintain 100% efficiency with 1 data point per partition until 100% coverage achieved  May also be useful to preferentially test partitions according to importance or likelihood of error Limits of Testing  Cannot prove correctness (nor can anything else)  ‘Pure’ wrapper function allows testing of its outputs, but what if the API writes unexpected data?  Need to review code, not just requirements, as part of domain analysis Database API as Mathematical Function: Insights into Testing
  • 38. Phases of Testing 1: Development Brendan Furey, 2018 38  In the development phase test code changes repeatedly with base code  At the end of development, base code may be safely re-factored using fixed test code  Dependencies do not change in general over relatively short timescale Database API as Mathematical Function: Insights into Testing
  • 39. Phases of Testing 2: Regression Brendan Furey, 2018 39  In the regression phase test code is executed repeatedly to check dependencies  Dependencies may change over relatively long timescale Database API as Mathematical Function: Insights into Testing
  • 40. Automated Testing: Why, When, What? Brendan Furey, 2018 40 Why Automate?  In manual testing we often use whatever data are present at the time  Saves effort of creating test data, but…  …cannot automate as inputs, and hence outputs, not known to testing program  Automating takes significantly more effort to do initially, BUT negligible effort to repeat When to Automate?  Whenever repeated testing is important…  Large projects with ongoing development over years  Agile methodology with frequent iterations adding functionality (CI/CD)  Ease of re-factoring desired  Otherwise manual testing is cheaper, and a valid option What to Automate?  Only automate testing of the entry-point APIs, not lower level subprograms  Within testing of an API, can mix automated and manual  May be difficult to automate testing of some features, eg some exception handling cases Database API as Mathematical Function: Insights into Testing
  • 41. Test Only the Top-Level API, with Dependencies Brendan Furey, 2018 41  Diagram represents testing API code as a whole, leaving dependency intact  This is the preferred pattern Database API as Mathematical Function: Insights into Testing
  • 42. Avoid Dependency Injection and Low-Level Tests Brendan Furey, 2018 42  Diagram represents mocking of dependency, and testing API code in small subprograms  This is an antipattern approach, to be avoided, causing…  Multiplication of test programs  Internal interactions become integrations, no longer in scope of unit testing  Refactoring of API no longer tested  Breaking dependency changes no longer captured in regression testing Database API as Mathematical Function: Insights into Testing
  • 43. Homeopathic Unit Testing Brendan Furey, 2018 43 3GL (eg Java) Unit Testing  Test complexity often regarded as a ‘code smell’  Aim to test code in small chunks and in isolation  Mock any dependencies Database Testing  Database API in PL/SQL embedding SQL  Aim to do ‘heavy lifting’ in SQL, which is a 4GL  Breaking into small chunks the ‘code smell’ here  Want to test dependencies continue to be consistent in regression phase Homeopathic Unit Testing  …testing small code sections without dependencies or significant structure  Regression tests are to test re-factoring and dependency changes Database API as Mathematical Function: Insights into Testing
  • 44. Conclusion Brendan Furey, 2018 Database API as Mathematical Function: Insights into Testing 44 Conclusion Highlighting the value gained from viewing database APIs and other code from the perspective of the mathematical function for both functional and performance testing
  • 45. Value of the Mathematical Function in Functional Testing Brendan Furey, 2018 45  Universal design pattern via ‘pure’ wrapper function around API  Provides standard template for programs  Resolves ‘brittleness’ caused by database impurity issues  Wrapper parameters may be seen as the ‘extended signature’ of the API  General 3-level data model for function inputs and outputs, expected and actual  Centralizes assertion in one library call, simplifying code  Data driven testing results in cleaner code and better testing  Test analysis and coverage benefit from domain partitioning approach Database API as Mathematical Function: Insights into Testing
  • 46. Value of the Mathematical Function in Performance Testing Brendan Furey, 2018 46 Dimensional Performance Benchmarking of SQL - IOUG Presentation, 2017  Consider the resource usage of a query (or any code) to vary as a function of problem size  As with functional testing, set up and clear the test data programmatically  Call the function under test in a loop over a range of sizing dimension values  Sizing dimension can be anything that affects performance, such as number of records  Performance measure can be elapsed or CPU time, or any Oracle-instrumented measure  Gives useful information about comparative performance and scalability of different methods  Frameworks for automated testing, both functional and performance, available here: Brendan’s GitHub Page  Performance variation can often be expressed as a function of sizing dimension  Sampling across a range allows us to estimate the form of the function Database API as Mathematical Function: Insights into Testing
  • 47. References 1. A Programmer Writes… (Brendan's Blog) 2. Guarding your data behind a hard shell PL/SQL API, OOW 2017 3. Why use PL/SQL?, 2015 4. Function (mathematics) - Wikipedia 5. Functional Programming: Pure Functions 6. GitHub: trapit_oracle_tester 7. Why code coverage is not a reliable metric 8. Email address validation 9. Map (higher-order function) 10. Dimensional Performance Benchmarking of SQL - IOUG Presentation, 2017 Brendan Furey, 2018 47Database API as Mathematical Function: Insights into Testing