Game updates improvements

* Added a set of tables which define game updates and their targets.
These definitions replace the old enumerate type. Added a set of
triggers which automatically create specific update tables, insert
missing entries, etc... when game update types are being manipulated.

* Removed manual insertion of game updates from empire creation
function and universe generator.

* Added registration of core update targets (i.e. planets and empires),
updated all existing game update processing functions and added type
registrations

* Created Maven project for game updates control components, moved
existing components from the -simple project, rewritten most of what
they contained, added new components for server-side update batch
processing
This commit is contained in:
Emmanuel BENOîT 2012-02-03 16:25:03 +01:00
parent ba6a1e2b41
commit 56eddcc4f0
93 changed files with 4004 additions and 578 deletions
legacyworlds-server-data/db-structure/tests/admin/040-functions

View file

@ -0,0 +1,70 @@
/*
* Tests of the update target definitions
*/
BEGIN;
-- Make sure we get rid of all existing definitions first
DELETE FROM sys.update_types;
DELETE FROM sys.update_targets;
-- Create a test schema & table which will be used as the target
CREATE SCHEMA test
CREATE TABLE test(
test_id SERIAL NOT NULL PRIMARY KEY
)
CREATE TABLE test2(
test_id SERIAL NOT NULL PRIMARY KEY
);
-- ***** TESTS BEGIN HERE *****
SELECT plan( 8 );
SELECT diag_test_name( 'Update target definitions - Failure if schema/table do not exist' );
SELECT throws_ok(
$$ INSERT INTO sys.update_targets(
updtgt_name , updtgt_schema , updtgt_table
) VALUES (
'Test' , 'test' , 'does_not_exist'
); $$ ,
23503
);
SELECT diag_test_name( 'Update target definitions - Successful insertion' );
SELECT lives_ok( $$
INSERT INTO sys.update_targets(
updtgt_name , updtgt_schema , updtgt_table
) VALUES (
'Test' , 'test' , 'test'
);
$$ );
SELECT diag_test_name( 'Update target definitions - Specific update table - Exists after insertion' );
SELECT has_table( 'test' , 'test_updates' , 'No specific update table' );
SELECT diag_test_name( 'Update target definitions - Specific update table - Primary key' );
SELECT index_is_primary( 'test' , 'test_updates' , 'test_updates_pkey' );
SELECT diag_test_name( 'Update target definitions - Specific update table - Primary key definition' );
SELECT has_index( 'test' , 'test_updates' , 'test_updates_pkey' ,
ARRAY[ 'updtgt_id' , 'updtype_id' , 'update_id' , 'test_id' ] );
SELECT diag_test_name( 'Update target definitions - Duplicate name' );
SELECT throws_ok( $$
INSERT INTO sys.update_targets(
updtgt_name , updtgt_schema , updtgt_table
) VALUES (
'Test' , 'test' , 'test2'
);
$$ , 23505 );
SELECT diag_test_name( 'Update target definitions - Duplicate table reference' );
SELECT throws_ok( $$
INSERT INTO sys.update_targets(
updtgt_name , updtgt_schema , updtgt_table
) VALUES (
'Test 2' , 'test' , 'test'
);
$$ , 23505 );
SELECT diag_test_name( 'Update target definitions - Deletion drops the specific update table' );
DELETE FROM sys.update_targets;
SELECT hasnt_table( 'test' , 'test_updates' , 'Specific update table still exists' );
SELECT * FROM finish( );
ROLLBACK;

View file

@ -0,0 +1,150 @@
/*
* Tests of the update type definitions
*/
BEGIN;
-- Make sure we get rid of all existing definitions first
DELETE FROM sys.update_types;
DELETE FROM sys.update_targets;
-- Create a test schema & tables which will be used as targets
CREATE SCHEMA test
CREATE TABLE test(
test_id SERIAL NOT NULL PRIMARY KEY
);
-- Create target definitions
INSERT INTO sys.update_targets(
updtgt_id , updtgt_name , updtgt_schema , updtgt_table
) VALUES (
1 , 'Test 1' , 'test' , 'test'
);
-- Create a dummy stored procedure in the sys schema
CREATE FUNCTION sys.dummy_update_func( c_tick BIGINT )
RETURNS INT LANGUAGE SQL AS 'SELECT 1;';
-- ***** TESTS BEGIN HERE *****
SELECT plan( 14 );
SELECT diag_test_name( 'Update types - Definition with invalid target' );
SELECT throws_ok( $$
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering
) VALUES (
1 , 5 , 'Test' , '' , 1
);
$$ , 23503 );
SELECT diag_test_name( 'Update types - Definition with invalid stored procedure name' );
SELECT throws_ok( $$
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering , updtype_proc_name
) VALUES (
1 , 5 , 'Test' , '' , 1 , 'does_not_exist'
);
$$ , 'P0001' );
SELECT diag_test_name( 'Update types - Successful insertion with no procedure name' );
SELECT lives_ok( $$
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering
) VALUES (
1 , 1 , 'Test' , '' , 1
);
$$ );
DELETE FROM sys.update_types;
SELECT diag_test_name( 'Update types - Successful insertion with a procedure name' );
SELECT lives_ok( $$
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering , updtype_proc_name
) VALUES (
1 , 1 , 'Test' , '' , 1 , 'dummy_update_func'
);
$$ );
SELECT diag_test_name( 'Update types - Setting an existing row''s stored procedure to something invalid fails' );
SELECT throws_ok( $$
UPDATE sys.update_types
SET updtype_proc_name = 'does_not_exist'
WHERE updtype_id = 1
$$ , 'P0001' );
SELECT diag_test_name( 'Update types - Failure on duplicate name' );
SELECT throws_ok( $$
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering
) VALUES (
2 , 1 , 'Test' , '' , 1
);
$$ , 23505 );
SELECT diag_test_name( 'Update types - Failure on duplicate stored procedure' );
SELECT throws_ok( $$
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering , updtype_proc_name
) VALUES (
3 , 1 , 'Test 2' , '' , 1 , 'dummy_update_func'
);
$$ , 23505 );
SELECT diag_test_name( 'Update types - Target deletion fails if type definitions exist' );
SELECT throws_ok( $$ DELETE FROM sys.update_targets WHERE updtgt_id = 1 $$ , 23503 );
DELETE FROM sys.update_types;
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering
) VALUES (
1 , 1 , 'Test 1' , '' , 1
) , (
2 , 1 , 'Test 3' , '' , 75
) , (
3 , 1 , 'Test 2' , '' , 2
);
SELECT diag_test_name( 'Update types - Ordering column is updated' );
SELECT set_eq(
$$ SELECT updtype_id , updtype_ordering FROM sys.update_types $$ ,
$$ VALUES ( 1 , 2 ) , ( 3 , 4 ) , ( 2 , 6 ) $$
);
DELETE FROM sys.update_types;
INSERT INTO test.test VALUES ( 1 ) , ( 2 );
INSERT INTO sys.update_types(
updtype_id , updtgt_id , updtype_name , updtype_description , updtype_ordering
) VALUES (
1 , 1 , 'Test 1' , '' , 1
);
SELECT diag_test_name( 'Update types - Type creation adds specific rows for missing items' );
SELECT set_eq(
$$ SELECT updtgt_id , updtype_id , test_id FROM test.test_updates $$ ,
$$ VALUES ( 1 , 1 , 1 ) , ( 1 , 1 , 2 ) $$
);
SELECT diag_test_name( 'Update types - Type creation adds genertic rows for missing items' );
SELECT set_eq(
$$ SELECT test_id , update_state , update_last
FROM test.test_updates
INNER JOIN sys.updates USING ( updtgt_id , updtype_id , update_id ) $$ ,
$$ VALUES ( 1 , 'FUTURE'::sys.update_state_type , -1 ) ,
( 2 , 'FUTURE'::sys.update_state_type , '-1' ) $$
);
INSERT INTO test.test VALUES ( 3 );
SELECT diag_test_name( 'Update types - New items have automatically inserted update rows' );
SELECT set_eq(
$$ SELECT test_id , updtype_id , update_state , update_last
FROM test.test_updates
INNER JOIN sys.updates USING ( updtgt_id , updtype_id , update_id )
WHERE test_id = 3 $$ ,
$$ VALUES ( 3 , 1 , 'FUTURE'::sys.update_state_type , -1 ) $$
);
DELETE FROM sys.update_types WHERE updtype_id = 1;
SELECT diag_test_name( 'Update types - Type deletion cascades to specific rows' );
SELECT is_empty( $$ SELECT * FROM test.test_updates $$ );
SELECT diag_test_name( 'Update types - Type deletion cascades to generic rows' );
SELECT is_empty( $$ SELECT * FROM sys.updates $$ );
SELECT * FROM finish( );
ROLLBACK;

View file

@ -16,7 +16,7 @@ BEGIN;
SELECT _create_emp_names( 1 , 'testEmp' );
/***** TESTS BEGIN HERE *****/
SELECT plan( 8 );
SELECT plan( 7 );
SELECT emp.create_empire( _get_emp_name( 'testEmp1' ) ,
_get_map_name( 'testPlanet1' ) ,
@ -57,16 +57,5 @@ BEGIN;
FROM emp.resources
WHERE empire_id = _get_emp_name( 'testEmp1' );
SELECT diag_test_name( 'emp.create_empire() - Empire update records' );
SELECT is( _eur.quantity , _utv.quantity)
FROM (
SELECT COUNT(*) AS quantity FROM emp.updates
WHERE empire_id = _get_emp_name( 'testEmp1' )
) AS _eur , (
SELECT COUNT(*) AS quantity
FROM unnest( enum_range( NULL::update_type ) ) AS _row
WHERE _row::TEXT LIKE 'EMPIRE_%'
) AS _utv;
SELECT * FROM finish( );
ROLLBACK;