File size: 3,105 Bytes
2795186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package testsuite.simple;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import testsuite.regression.ConnectionRegressionTest;

public class ReadOnlyCallableStatementTest extends ConnectionRegressionTest {
	public ReadOnlyCallableStatementTest(String name) {
		super(name);
	}

	public void testReadOnlyWithProcBodyAccess() throws Exception {
		if (versionMeetsMinimum(5, 0)) {
			Connection replConn = null;
			Properties props = getMasterSlaveProps();
			props.setProperty("autoReconnect", "true");
	
			
			try {
				createProcedure("testProc1", "()\n"
								+ "READS SQL DATA\n"
								+ "begin\n"
								+ "SELECT NOW();\n"
								+ "end\n");

				createProcedure("`testProc.1`", "()\n"
						+ "READS SQL DATA\n"
						+ "begin\n"
						+ "SELECT NOW();\n"
						+ "end\n");
				
				replConn = getMasterSlaveReplicationConnection();
				replConn.setReadOnly(true);
				
				CallableStatement stmt = replConn.prepareCall("CALL testProc1()");
				stmt.execute();
				stmt.execute();
				
				stmt = replConn.prepareCall("CALL test.testProc1()");
				stmt.execute();
				
				stmt = replConn.prepareCall("CALL test.`testProc.1`()");
				stmt.execute();
				
			} finally {
			
				closeMemberJDBCResources();
				
				if (replConn != null) {
					replConn.close();
				}
			}
		}
	}
	
	public void testNotReadOnlyWithProcBodyAccess() throws Exception {
		if (versionMeetsMinimum(5, 0)) {
			
			Connection replConn = null;
			Properties props = getMasterSlaveProps();
			props.setProperty("autoReconnect", "true");
		
			
			try {
				createProcedure("testProc2", "()\n"
								+ "MODIFIES SQL DATA\n"
								+ "begin\n"
								+ "SELECT NOW();\n"
								+ "end\n");

				createProcedure("`testProc.2`", "()\n"
						+ "MODIFIES SQL DATA\n"
						+ "begin\n"
						+ "SELECT NOW();\n"
						+ "end\n");
				
				replConn = getMasterSlaveReplicationConnection();
				replConn.setReadOnly(true);
				
				CallableStatement stmt = replConn.prepareCall("CALL testProc2()");

				try{
					stmt.execute();
					fail("Should not execute because procedure modifies data.");
				} catch (SQLException e) {
					assertEquals("Should error for read-only connection.", e.getSQLState(), "S1009");
				}

				stmt = replConn.prepareCall("CALL test.testProc2()");

				try{
					stmt.execute();
					fail("Should not execute because procedure modifies data.");
				} catch (SQLException e) {
					assertEquals("Should error for read-only connection.", e.getSQLState(), "S1009");
				}

				stmt = replConn.prepareCall("CALL test.`testProc.2`()");

				try{
					stmt.execute();
					fail("Should not execute because procedure modifies data.");
				} catch (SQLException e) {
					assertEquals("Should error for read-only connection.", e.getSQLState(), "S1009");
				}

				
			} finally {
			
				closeMemberJDBCResources();
				
				if (replConn != null) {
					replConn.close();
				}
			}
		}
	}
	


}