1-
21import unittest
2+ import gzip
3+ from typing import Dict , Any
34from crate .qa .tests import NodeProvider , wait_for_active_shards
45from crate .client import connect
6+ from urllib .request import urlopen
7+ import json
8+
9+
10+ def init_data (c ):
11+ c .execute (
12+ """
13+ create function foo(int)
14+ returns int
15+ language javascript
16+ as 'function foo(x) { return 42 + x; }'
17+ """
18+ )
19+ c .execute ('CREATE TABLE tbl (x int)' )
20+ c .execute ('INSERT INTO tbl (x) values (?)' , (10 ,))
21+ c .execute ("refresh table tbl" )
22+ c .execute ("create view v1 as (select * from tbl)" )
23+ c .execute ("create user arthur with (password = 'secret')" )
24+ c .execute ("grant dql to arthur" )
25+ c .execute ("create table tparted (x int, y as foo(0), p int) partitioned by (p)" )
26+ c .execute ("insert into tparted (x, p) values (1, 1)" )
27+ c .execute ("refresh table tparted" )
28+
29+
30+ def fetch_versions () -> Dict [str , Any ]:
31+ with urlopen ('https://cratedb.com/releases.json' ) as r :
32+ if r .headers .get ('Content-Encoding' ) == 'gzip' :
33+ with gzip .open (r , 'rt' ) as r :
34+ return json .loads (r .read ())
35+ else :
36+ return json .loads (r .read ().decode ('utf-8' ))
537
638
739class HotfixDowngradeTest (NodeProvider , unittest .TestCase ):
840
9- def test_latest_testing_can_be_downgraded_within_hotfix_versions (self ):
10- cluster = self ._new_cluster ('latest-testing' , 2 )
11- cluster .start ()
12- node = cluster .node ()
13- with connect (node .http_url , error_trace = True ) as conn :
14- c = conn .cursor ()
15- c .execute ('CREATE TABLE tbl (x int)' )
16- c .execute ('INSERT INTO tbl (x) values (?)' , (10 ,))
41+ def _run_downgrades (self , node ):
1742 major , feature , hotfix = node .version
18- for i in range (hotfix , - 1 , - 1 ):
43+ for i in range (hotfix - 1 , - 1 , - 1 ):
1944 new_version = (major , feature , i )
2045 with self .subTest (version = new_version ):
2146 node = self .upgrade_node (node , '.' .join (map (str , new_version )))
@@ -26,3 +51,24 @@ def test_latest_testing_can_be_downgraded_within_hotfix_versions(self):
2651 c .execute ('SELECT x FROM tbl' )
2752 xs = [row [0 ] for row in c .fetchall ()]
2853 self .assertEqual (xs , [10 ])
54+
55+ def test_can_downgrade_latest_testing_within_hotfix_versions (self ):
56+ cluster = self ._new_cluster ('latest-testing' , 2 )
57+ cluster .start ()
58+ node = cluster .node ()
59+ with connect (node .http_url , error_trace = True ) as conn :
60+ init_data (conn .cursor ())
61+
62+ self ._run_downgrades (node )
63+ cluster .stop ()
64+
65+ def test_can_downgrade_unreleased_testing_branch_within_hotfix_versions (self ):
66+ versions = fetch_versions ()
67+ version = versions ["testing" ]["version" ]
68+ major , minor , hotfix = version .split ("." , maxsplit = 3 )
69+ cluster = self ._new_cluster (f"{ major } .{ minor } " , 2 )
70+ cluster .start ()
71+ node = cluster .node ()
72+ with connect (node .http_url , error_trace = True ) as conn :
73+ init_data (conn .cursor ())
74+ self ._run_downgrades (node )
0 commit comments