Search in sources :

Example 1 with CreateSessionRequest

use of com.swiftmq.jms.smqp.v610.CreateSessionRequest in project java-spanner by googleapis.

the class SpannerClientTest method createSessionTest.

@Test
public void createSessionTest() throws Exception {
    Session expectedResponse = Session.newBuilder().setName(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setApproximateLastUseTime(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    Session actualResponse = client.createSession(database);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSessionRequest actualRequest = ((CreateSessionRequest) actualRequests.get(0));
    Assert.assertEquals(database.toString(), actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) DatabaseName(com.google.spanner.v1.DatabaseName) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 2 with CreateSessionRequest

use of com.swiftmq.jms.smqp.v610.CreateSessionRequest in project java-spanner by googleapis.

the class SpannerClientTest method createSessionTest2.

@Test
public void createSessionTest2() throws Exception {
    Session expectedResponse = Session.newBuilder().setName(SessionName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]", "[SESSION]").toString()).putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setApproximateLastUseTime(Timestamp.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    String database = "database1789464955";
    Session actualResponse = client.createSession(database);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSessionRequest actualRequest = ((CreateSessionRequest) actualRequests.get(0));
    Assert.assertEquals(database, actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) AbstractMessage(com.google.protobuf.AbstractMessage) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 3 with CreateSessionRequest

use of com.swiftmq.jms.smqp.v610.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerLoadTest method createAsyncSessions.

private static List<String> createAsyncSessions(SpannerStub stub) throws InterruptedException {
    List<AsyncResponseObserver<Session>> resps = new ArrayList<>();
    List<String> respNames = new ArrayList<>();
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE).build();
    for (int i = 0; i < MAX_CHANNEL * MAX_STREAM / 2; i++) {
        AsyncResponseObserver<Session> resp = new AsyncResponseObserver<Session>();
        stub.createSession(req, resp);
        resps.add(resp);
    }
    for (AsyncResponseObserver<Session> resp : resps) {
        respNames.add(resp.get().getName());
    }
    return respNames;
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) ArrayList(java.util.ArrayList) Session(com.google.spanner.v1.Session)

Example 4 with CreateSessionRequest

use of com.swiftmq.jms.smqp.v610.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method testUnbindWithInvalidAffinityKey.

@Test
public void testUnbindWithInvalidAffinityKey() {
    SpannerBlockingStub stub = getSpannerBlockingStub();
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
    Session session = stub.createSession(req);
    expectedEx.expect(StatusRuntimeException.class);
    expectedEx.expectMessage("INVALID_ARGUMENT: Invalid DeleteSession request.");
    // No channel bound with the key "invalid_session", will use the least busy one.
    stub.deleteSession(DeleteSessionRequest.newBuilder().setName("invalid_session").build());
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 5 with CreateSessionRequest

use of com.swiftmq.jms.smqp.v610.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method createFutureSessions.

private List<String> createFutureSessions(SpannerFutureStub stub) throws Exception {
    List<ListenableFuture<Session>> futures = new ArrayList<>();
    List<String> futureNames = new ArrayList<>();
    assertEquals(ConnectivityState.IDLE, gcpChannel.getState(false));
    // Check CreateSession with multiple channels and streams,
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
    for (int i = 0; i < MAX_CHANNEL * MAX_STREAM; i++) {
        ListenableFuture<Session> future = stub.createSession(req);
        futures.add(future);
    }
    checkChannelRefs(MAX_CHANNEL, MAX_STREAM, 0);
    for (ListenableFuture<Session> future : futures) {
        futureNames.add(future.get().getName());
    }
    // Since createSession will bind the key, check the number of keys bound with channels.
    assertEquals(ConnectivityState.READY, gcpChannel.getState(false));
    assertEquals(MAX_CHANNEL * MAX_STREAM, gcpChannel.affinityKeyToChannelRef.size());
    checkChannelRefs(MAX_CHANNEL, 0, MAX_STREAM);
    return futureNames;
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) ArrayList(java.util.ArrayList) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Session(com.google.spanner.v1.Session)

Aggregations

CreateSessionRequest (com.google.spanner.v1.CreateSessionRequest)11 Session (com.google.spanner.v1.Session)11 JMSException (javax.jms.JMSException)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 SpannerBlockingStub (com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub)4 IllegalStateException (javax.jms.IllegalStateException)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 CreateSessionReply (com.swiftmq.jms.smqp.v600.CreateSessionReply)2 CreateSessionRequest (com.swiftmq.jms.smqp.v600.CreateSessionRequest)2 CreateSessionReply (com.swiftmq.jms.smqp.v610.CreateSessionReply)2 CreateSessionRequest (com.swiftmq.jms.smqp.v610.CreateSessionRequest)2 CreateSessionReply (com.swiftmq.jms.smqp.v630.CreateSessionReply)2 CreateSessionRequest (com.swiftmq.jms.smqp.v630.CreateSessionRequest)2 CreateSessionReply (com.swiftmq.jms.smqp.v750.CreateSessionReply)2 CreateSessionRequest (com.swiftmq.jms.smqp.v750.CreateSessionRequest)2 HashMap (java.util.HashMap)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1