-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
279 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
33 changes: 33 additions & 0 deletions
33
clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseSocketFactory.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,33 @@ | ||
package com.clickhouse.client; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Generic factory interface for creating sockets used by the TCP and Apache | ||
* Http clients. | ||
*/ | ||
public interface ClickHouseSocketFactory { | ||
/** | ||
* Creates a new instance of the provided configuration and class type. | ||
* | ||
* @param <T> type of class to create | ||
* @param config configuration | ||
* @param clazz class instance for the type to instantiate | ||
* @return non-null new instance of the given class | ||
* @throws IOException when failed to create the instance | ||
* @throws UnsupportedOperationException when the given class is not supported | ||
*/ | ||
<T> T create(ClickHouseConfig config, Class<T> clazz) throws IOException, UnsupportedOperationException; | ||
|
||
/** | ||
* Tests whether this factory supports creating instances of the given class | ||
* type. For example, before calling {@link #create(ClickHouseConfig, Class)}, | ||
* you may want to call this method first to verify the factory can produce the | ||
* desired type. | ||
* | ||
* @param clazz non-null class reflecting the type to check support for | ||
* @return true if the factory supports creating instances of the given type; | ||
* false otherwise | ||
*/ | ||
boolean supports(Class<?> clazz); | ||
} |
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
45 changes: 45 additions & 0 deletions
45
clickhouse-client/src/test/java/com/clickhouse/client/AbstractSocketClientTest.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,45 @@ | ||
package com.clickhouse.client; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class AbstractSocketClientTest { | ||
public static class CustomListFactory implements ClickHouseSocketFactory { | ||
@Override | ||
public <T> T create(ClickHouseConfig config, Class<T> clazz) throws IOException, UnsupportedOperationException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean supports(Class<?> clazz) { | ||
return List.class.isAssignableFrom(clazz); | ||
} | ||
} | ||
|
||
@Test(groups = { "unit" }) | ||
public void testGetCustomSocketFactory() { | ||
CustomListFactory defaultFactory = new CustomListFactory(); | ||
|
||
Assert.assertEquals(AbstractSocketClient.getCustomSocketFactory(null, null, null), null); | ||
Assert.assertEquals(AbstractSocketClient.getCustomSocketFactory(null, defaultFactory, null), defaultFactory); | ||
Assert.assertEquals(AbstractSocketClient.getCustomSocketFactory("", defaultFactory, null), defaultFactory); | ||
|
||
Assert.assertEquals(AbstractSocketClient.getCustomSocketFactory(CustomListFactory.class.getName(), | ||
defaultFactory, List.class), | ||
AbstractSocketClient.getCustomSocketFactory(CustomListFactory.class.getName(), | ||
defaultFactory, List.class)); | ||
|
||
ClickHouseSocketFactory factory = AbstractSocketClient.getCustomSocketFactory(CustomListFactory.class.getName(), | ||
defaultFactory, List.class); | ||
Assert.assertEquals(factory.getClass(), defaultFactory.getClass()); | ||
Assert.assertNotEquals(factory, defaultFactory); | ||
|
||
factory = AbstractSocketClient.getCustomSocketFactory(CustomListFactory.class.getName(), | ||
defaultFactory, Map.class); | ||
Assert.assertEquals(factory, defaultFactory); | ||
} | ||
} |
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
Oops, something went wrong.