本文整理了Java中org.apache.ignite.Ignition.startClient()
方法的一些代码示例,展示了Ignition.startClient()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignition.startClient()
方法的具体详情如下:
包路径:org.apache.ignite.Ignition
类名称:Ignition
方法名:startClient
[英]Initializes new instance of IgniteClient.
Server connection will be lazily initialized when first required.
[中]初始化IgniteClient的新实例。
当第一次需要时,服务器连接将被延迟初始化。
代码示例来源:origin: apache/ignite
@Override public Object call() {
Ignition.startClient(getClientConfiguration());
return null;
}
},
代码示例来源:origin: apache/ignite
/**
* Test client fails on start if server is unavailable
*/
@Test
public void testClientFailsOnStart() {
ClientConnectionException expEx = null;
try (IgniteClient ignored = Ignition.startClient(getClientConfiguration())) {
// No-op.
}
catch (ClientConnectionException connEx) {
expEx = connEx;
}
catch (Exception ex) {
fail(String.format(
"%s expected but %s was received: %s",
ClientConnectionException.class.getName(),
ex.getClass().getName(),
ex
));
}
assertNotNull(
String.format("%s expected but no exception was received", ClientConnectionException.class.getName()),
expEx
);
}
代码示例来源:origin: apache/ignite
/**
* @param cipherSuites list of cipher suites
* @param protocols list of protocols
* @throws Exception If failed.
*/
private void checkSuccessfulClientStart(String[] cipherSuites, String[] protocols) throws Exception {
this.cipherSuites = F.isEmpty(cipherSuites) ? null : cipherSuites;
this.protocols = F.isEmpty(protocols) ? null : protocols;
try (IgniteClient client = Ignition.startClient(getClientConfiguration())) {
client.getOrCreateCache(TEST_CACHE_NAME);
}
}
代码示例来源:origin: apache/ignite
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))
) {
ClientCache<Integer, String> cache = client.createCache("testMultithreading");
代码示例来源:origin: apache/ignite
/** Test valid user authentication. */
@Test
public void testValidUserAuthentication() throws Exception {
final String USER = "joe";
final String PWD = "password";
try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD));
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)
.setUserName(USER)
.setUserPassword(PWD)
)
) {
client.getOrCreateCache("testAuthentication");
}
}
代码示例来源:origin: apache/ignite
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME);
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Person, Integer> cache = client.createCache("testBatchPutGet");
代码示例来源:origin: apache/ignite
/**
* Create user.
*/
private static void createUser(String user, String pwd) throws Exception {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration()
.setAddresses(Config.SERVER)
.setUserName("ignite")
.setUserPassword("ignite")
)) {
client.query(
new SqlFieldsQuery(String.format("CREATE USER \"%s\" WITH PASSWORD '%s'", user, pwd))
).getAll();
}
}
}
代码示例来源:origin: apache/ignite
public void testBinaryQueries() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))
) {
final String TYPE_NAME = "Person";
代码示例来源:origin: apache/ignite
/** Test user cannot create user. */
@Test
public void testUserCannotCreateUser() throws Exception {
final String USER = "joe";
final String PWD = "password";
try (Ignite ignored = igniteWithAuthentication(new SimpleEntry<>(USER, PWD));
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)
.setUserName(USER)
.setUserPassword(PWD)
)
) {
Exception authError = null;
try {
client.query(
new SqlFieldsQuery(String.format("CREATE USER \"%s\" WITH PASSWORD '%s'", "joe2", "password"))
).getAll();
}
catch (Exception e) {
authError = e;
}
assertNotNull("User created another user", authError);
}
}
代码示例来源:origin: apache/ignite
public void testCacheManagement() throws Exception {
try (LocalIgniteCluster ignored = LocalIgniteCluster.start(2);
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
final String CACHE_NAME = "testCacheManagement";
代码示例来源:origin: apache/ignite
public void testBinaryObjectApi() throws Exception {
try (Ignite srv = Ignition.start(Config.getServerConfiguration())) {
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
代码示例来源:origin: apache/ignite
/**
* Tested API:
* <ul>
* <li>{@link IgniteClient#query(SqlFieldsQuery)}</li>
* </ul>
*/
@Test
public void testSql() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))
) {
client.query(
new SqlFieldsQuery(String.format(
"CREATE TABLE IF NOT EXISTS Person (id INT PRIMARY KEY, name VARCHAR) WITH \"VALUE_TYPE=%s\"",
Person.class.getName()
)).setSchema("PUBLIC")
).getAll();
int key = 1;
Person val = new Person(key, "Person 1");
client.query(new SqlFieldsQuery(
"INSERT INTO Person(id, name) VALUES(?, ?)"
).setArgs(val.getId(), val.getName()).setSchema("PUBLIC"))
.getAll();
Object cachedName = client.query(
new SqlFieldsQuery("SELECT name from Person WHERE id=?").setArgs(key).setSchema("PUBLIC")
).getAll().iterator().next().iterator().next();
assertEquals(val.getName(), cachedName);
}
}
代码示例来源:origin: apache/ignite
public void testGettingEmptyResultWhenQueryingEmptyTable() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))
) {
final String TBL = "Person";
代码示例来源:origin: apache/ignite
/** Test valid user authentication. */
@Test
public void testInvalidUserAuthentication() {
Exception authError = null;
try (Ignite ignored = igniteWithAuthentication();
IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER)
.setUserName("JOE")
.setUserPassword("password")
)
) {
client.getOrCreateCache("testAuthentication");
}
catch (Exception e) {
authError = e;
}
assertNotNull("Authentication with invalid credentials succeeded", authError);
assertTrue("Invalid type of authentication error", authError instanceof ClientAuthenticationException);
}
代码示例来源:origin: apache/ignite
/**
* Unmarshalling schema-less Ignite binary objects into Java static types.
*/
@Test
public void testUnmarshalSchemalessIgniteBinaries() throws Exception {
int key = 1;
Person val = new Person(key, "Joe");
try (Ignite srv = Ignition.start(Config.getServerConfiguration())) {
// Add an entry directly to the Ignite server. This stores a schema-less object in the cache and
// does not register schema in the client's metadata cache.
srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val);
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
ClientCache<Integer, Person> cache = client.cache(Config.DEFAULT_CACHE_NAME);
Person cachedVal = cache.get(key);
assertEquals(val, cachedVal);
}
}
}
代码示例来源:origin: apache/ignite
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Integer, Person> cache = client.getOrCreateCache(Config.DEFAULT_CACHE_NAME);
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Person, Integer> cache = client.getOrCreateCache("testPutGet");
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Person, Person> cache = client.getOrCreateCache("testPutGet");
代码示例来源:origin: apache/ignite
/**
* Reading schema-less Ignite Binary object.
*/
@Test
public void testReadingSchemalessIgniteBinaries() throws Exception {
int key = 1;
Person val = new Person(key, "Joe");
try (Ignite srv = Ignition.start(Config.getServerConfiguration())) {
// Add an entry directly to the Ignite server. This stores a schema-less object in the cache and
// does not register schema in the client's metadata cache.
srv.cache(Config.DEFAULT_CACHE_NAME).put(key, val);
try (IgniteClient client = Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))) {
ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
BinaryObject cachedVal = cache.get(key);
assertEquals(val.getId(), cachedVal.field("id"));
assertEquals(val.getName(), cachedVal.field("name"));
}
}
}
代码示例来源:origin: apache/ignite
/**
* Put/get operations with Ignite Binary Object API
*/
@Test
public void testBinaryObjectPutGet() throws Exception {
int key = 1;
try (Ignite ignored = Ignition.start(Config.getServerConfiguration())) {
try (IgniteClient client =
Ignition.startClient(new ClientConfiguration().setAddresses(Config.SERVER))
) {
IgniteBinary binary = client.binary();
BinaryObject val = binary.builder("Person")
.setField("id", 1, int.class)
.setField("name", "Joe", String.class)
.build();
ClientCache<Integer, BinaryObject> cache = client.cache(Config.DEFAULT_CACHE_NAME).withKeepBinary();
cache.put(key, val);
BinaryObject cachedVal =
client.cache(Config.DEFAULT_CACHE_NAME).<Integer, BinaryObject>withKeepBinary().get(key);
assertBinaryObjectsEqual(val, cachedVal);
}
}
}
代码示例来源:origin: apache/ignite
public void testRemoveReplace() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Integer, String> cache = client.createCache("testRemoveReplace");
代码示例来源:origin: apache/ignite
/**
* Tested API:
* <ul>
* <li>{@link ClientCache#getAndPut(Object, Object)}</li>
* <li>{@link ClientCache#getAndRemove(Object)}</li>
* <li>{@link ClientCache#getAndReplace(Object, Object)}</li>
* <li>{@link ClientCache#putIfAbsent(Object, Object)}</li>
* </ul>
*/
@Test
public void testAtomicPutGet() throws Exception {
try (Ignite ignored = Ignition.start(Config.getServerConfiguration());
IgniteClient client = Ignition.startClient(getClientConfiguration())
) {
ClientCache<Integer, String> cache = client.createCache("testRemoveReplace");
assertNull(cache.getAndPut(1, "1"));
assertEquals("1", cache.getAndPut(1, "1.1"));
assertEquals("1.1", cache.getAndRemove(1));
assertNull(cache.getAndRemove(1));
assertTrue(cache.putIfAbsent(1, "1"));
assertFalse(cache.putIfAbsent(1, "1.1"));
assertEquals("1", cache.getAndReplace(1, "1.1"));
assertEquals("1.1", cache.getAndReplace(1, "1"));
assertNull(cache.getAndReplace(2, "2"));
}
}
内容来源于网络,如有侵权,请联系作者删除!