map) {
14 | #script#
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/resources/site/destination.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | mysql redis replicate web console
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
57 |
238 |
239 |
240 |
241 |
242 |
243 |
--------------------------------------------------------------------------------
/src/main/resources/site/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | mysql redis replicate web console
6 |
7 |
8 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | Destination |
25 | Run On |
26 | Run Fail |
27 | Monitor |
28 | |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | 注意:配置修改后需要重新加载才生效( STOP -> START)
41 |
42 |
43 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/src/test/doc/test_script.sql:
--------------------------------------------------------------------------------
1 |
2 | CREATE USER canal IDENTIFIED BY 'canal';
3 | GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
4 | -- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
5 | FLUSH PRIVILEGES;
6 |
7 | create database user_db charset utf8 ;
8 |
9 | use user_db ;
10 |
11 | create table user ( id int auto_increment , name varchar(100) , age smallint , height float , sex char(1) , comment text , birthday date , create_at timestamp , primary key (id) );
12 |
13 | insert into user (name , age , height , sex , comment , birthday , create_at ) values ('wens' , 29 , 165.66, 'M' , '音乐 读书 数学 编程' , '1986-01-06' , now() ) ;
14 |
--------------------------------------------------------------------------------
/src/test/java/mysql/redis/replicate/HttpClientUtilsTest.java:
--------------------------------------------------------------------------------
1 | package mysql.redis.replicate;
2 |
3 | import java.io.IOException;
4 | import java.io.OutputStream;
5 |
6 | /**
7 | * Created by wens on 15/12/6.
8 | */
9 | public class HttpClientUtilsTest {
10 |
11 | public static void main(String[] args) throws IOException, InterruptedException {
12 |
13 | Process nc = Runtime.getRuntime().exec("nc -l 9999");
14 | new Thread() {
15 | @Override
16 | public void run() {
17 | String ret = HttpClientUtils.post("http://localhost:9999/post", Tuple.of("name", "wens"));
18 | System.out.println(ret);
19 | }
20 | }.start();
21 |
22 | Thread.sleep(1000);
23 |
24 | StringBuffer resp = new StringBuffer();
25 |
26 | resp.append("HTTP/1.1 200 OK\n");
27 | resp.append("Content-Length: 2\n");
28 | resp.append("Content-Type: text/html; charset=utf-8\n\n");
29 | resp.append("ok");
30 | OutputStream outputStream = nc.getOutputStream();
31 | outputStream.write(resp.toString().getBytes());
32 | outputStream.flush();
33 | Thread.sleep(100);
34 |
35 |
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/mysql/redis/replicate/ZookeeperLeaderElectorTest.java:
--------------------------------------------------------------------------------
1 | package mysql.redis.replicate;
2 |
3 | import org.I0Itec.zkclient.ZkClient;
4 |
5 | import java.util.concurrent.BrokenBarrierException;
6 | import java.util.concurrent.CountDownLatch;
7 | import java.util.concurrent.CyclicBarrier;
8 | import java.util.concurrent.atomic.AtomicLong;
9 |
10 | /**
11 | * Created by wens on 15/12/5.
12 | */
13 | public class ZookeeperLeaderElectorTest {
14 |
15 | public static void main(String[] args) throws InterruptedException {
16 | final ZkClient zkClient = new ZkClient("localhost");
17 | ZkPathUtils.init("", zkClient);
18 |
19 | final AtomicLong atomicLong = new AtomicLong(0);
20 |
21 | final ZookeeperLeaderElector.LeaderListener leaderListener = new ZookeeperLeaderElector.LeaderListener() {
22 | public void onBecomingLeader() {
23 | atomicLong.incrementAndGet();
24 | }
25 | };
26 |
27 | int n = 3;
28 | final CountDownLatch countDownLatch = new CountDownLatch(n);
29 | final CyclicBarrier cyclicBarrier = new CyclicBarrier(n);
30 |
31 | for (int i = 0; i < n; i++) {
32 | final int ii = i;
33 | new Thread() {
34 | @Override
35 | public void run() {
36 | try {
37 | cyclicBarrier.await();
38 | } catch (InterruptedException e) {
39 | e.printStackTrace();
40 | } catch (BrokenBarrierException e) {
41 | e.printStackTrace();
42 | }
43 | new ZookeeperLeaderElector(String.valueOf(ii), leaderListener).start();
44 |
45 | countDownLatch.countDown();
46 | }
47 | }.start();
48 | }
49 |
50 | try {
51 | countDownLatch.await();
52 | } catch (InterruptedException e) {
53 | e.printStackTrace();
54 | }
55 |
56 | if (atomicLong.get() != 1) {
57 | throw new RuntimeException("Not pass");
58 | }
59 |
60 | zkClient.delete(ZkPathUtils.getControllerPath());
61 |
62 | Thread.sleep(1000);
63 |
64 | if (atomicLong.get() != 2) {
65 | throw new RuntimeException("Not pass");
66 | }
67 |
68 |
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/mysql/redis/replicate/canal/MysqlUtils.java:
--------------------------------------------------------------------------------
1 | package mysql.redis.replicate.canal;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.SQLException;
6 | import java.sql.Statement;
7 |
8 | /**
9 | * Created by wens on 15-10-15.
10 | */
11 | public class MysqlUtils {
12 |
13 |
14 | public static Connection getConnection(String user, String pwd, String url) throws SQLException {
15 | return DriverManager.getConnection(url, user, pwd);
16 | }
17 |
18 |
19 | public static void executeSQL(Connection connection, String sql) throws SQLException {
20 | Statement statement = null;
21 | try {
22 | statement = connection.createStatement();
23 | statement.execute(sql);
24 | } finally {
25 | if (statement != null) {
26 | statement.close();
27 | }
28 | }
29 | }
30 |
31 | public static void executeUpdateSQL(Connection connection, String sql) throws SQLException {
32 | Statement statement = null;
33 | try {
34 | statement = connection.createStatement();
35 | statement.executeUpdate(sql);
36 | } finally {
37 | if (statement != null) {
38 | statement.close();
39 | }
40 | }
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------