-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The establishment time and execution time for accessing the topology …
…can be configured. (#136)
- Loading branch information
1 parent
0d35e65
commit a205ef7
Showing
6 changed files
with
168 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/jd/jdbc/topo/etcd2topo/Etcd2TopoFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2021 JD Project Authors. Licensed under Apache-2.0. | ||
Copyright 2019 The Vitess Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.jd.jdbc.topo.etcd2topo; | ||
|
||
import java.lang.reflect.Field; | ||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class Etcd2TopoFactoryTest { | ||
@Test | ||
@Ignore | ||
public void testTopoConnectTimeout() throws Exception { | ||
long timeout = 50000; | ||
System.setProperty("vtdriver.topoConnectTimeout", timeout + ""); | ||
|
||
new Etcd2TopoFactory(); | ||
|
||
Field field = Etcd2TopoFactory.class.getDeclaredField("CONNECT_TIMEOUT_LONG"); | ||
field.setAccessible(true); | ||
long connectTimeoutLong = (long) field.get(null); | ||
Assert.assertEquals(timeout, connectTimeoutLong); | ||
} | ||
|
||
@Test | ||
public void testTopoConnectTimeout2() throws Exception { | ||
new Etcd2TopoFactory(); | ||
|
||
Field field = Etcd2TopoFactory.class.getDeclaredField("CONNECT_TIMEOUT_LONG"); | ||
field.setAccessible(true); | ||
long connectTimeoutLong = (long) field.get(null); | ||
Assert.assertEquals(5000, connectTimeoutLong); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/test/java/com/jd/jdbc/topo/etcd2topo/Etcd2TopoServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2021 JD Project Authors. Licensed under Apache-2.0. | ||
Copyright 2019 The Vitess Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package com.jd.jdbc.topo.etcd2topo; | ||
|
||
import com.jd.jdbc.context.VtContext; | ||
import com.jd.jdbc.topo.Topo; | ||
import com.jd.jdbc.topo.TopoServer; | ||
import com.jd.jdbc.vitess.VitessJdbcUrlParser; | ||
import java.lang.reflect.Field; | ||
import java.util.List; | ||
import java.util.Properties; | ||
import org.junit.Assert; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import testsuite.TestSuite; | ||
import testsuite.internal.TestSuiteShardSpec; | ||
|
||
public class Etcd2TopoServerTest extends TestSuite { | ||
|
||
@Test | ||
@Ignore | ||
public void testTopoExecuteTimeout() throws Exception { | ||
long timeout = 50000; | ||
System.setProperty("vtdriver.topoExecuteTimeout", timeout + ""); | ||
|
||
String connectionUrl = getConnectionUrl(Driver.of(TestSuiteShardSpec.TWO_SHARDS)); | ||
Properties prop = VitessJdbcUrlParser.parse(connectionUrl, null); | ||
String topoServerAddress = "http://" + prop.getProperty("host") + ":" + prop.getProperty("port"); | ||
TopoServer topoServer = Topo.getTopoServer(Topo.TopoServerImplementType.TOPO_IMPLEMENTATION_ETCD2, topoServerAddress); | ||
List<String> cells = topoServer.getAllCells(VtContext.withCancel(VtContext.background())); | ||
String cell = cells.get(0); | ||
topoServer.connForCell(null, cell); | ||
|
||
Field field = Etcd2TopoServer.class.getDeclaredField("DEFALUT_TIMEOUT"); | ||
field.setAccessible(true); | ||
long defalutTimeout = (long) field.get(null); | ||
Assert.assertEquals(timeout, defalutTimeout); | ||
} | ||
|
||
@Test | ||
public void testTopoExecuteTimeout2() throws Exception { | ||
String connectionUrl = getConnectionUrl(Driver.of(TestSuiteShardSpec.TWO_SHARDS)); | ||
Properties prop = VitessJdbcUrlParser.parse(connectionUrl, null); | ||
String topoServerAddress = "http://" + prop.getProperty("host") + ":" + prop.getProperty("port"); | ||
TopoServer topoServer = Topo.getTopoServer(Topo.TopoServerImplementType.TOPO_IMPLEMENTATION_ETCD2, topoServerAddress); | ||
List<String> cells = topoServer.getAllCells(VtContext.withCancel(VtContext.background())); | ||
String cell = cells.get(0); | ||
topoServer.connForCell(null, cell); | ||
|
||
Field field = Etcd2TopoServer.class.getDeclaredField("DEFALUT_TIMEOUT"); | ||
field.setAccessible(true); | ||
long defalutTimeout = (long) field.get(null); | ||
Assert.assertEquals(10000L, defalutTimeout); | ||
} | ||
} |