Search in sources :

Example 11 with CreateSessionRequest

use of com.google.spanner.v1.CreateSessionRequest in project swiftmq-client by iitsoftware.

the class TopicConnectionImpl method createTopicSession.

public TopicSession createTopicSession(boolean transacted, int acknowledgeMode) throws JMSException {
    verifyState();
    SessionImpl topicSession = null;
    CreateSessionReply reply = null;
    try {
        reply = (CreateSessionReply) requestRegistry.request(new CreateSessionRequest(0, transacted, acknowledgeMode, CreateSessionRequest.TOPIC_SESSION));
    } catch (Exception e) {
        throw ExceptionConverter.convert(e);
    }
    if (reply.isOk()) {
        int dispatchId = reply.getSessionDispatchId();
        String cid = clientID != null ? clientID : internalCID;
        topicSession = new SessionImpl(SessionImpl.TYPE_TOPIC_SESSION, this, transacted, acknowledgeMode, dispatchId, requestRegistry, myHostname, cid);
        topicSession.setUserName(userName);
        topicSession.setMyDispatchId(addRequestService(topicSession));
        addSession(topicSession);
    } else {
        throw ExceptionConverter.convert(reply.getException());
    }
    return (topicSession);
}
Also used : CreateSessionRequest(com.swiftmq.jms.smqp.v510.CreateSessionRequest) CreateSessionReply(com.swiftmq.jms.smqp.v510.CreateSessionReply) JMSException(javax.jms.JMSException)

Example 12 with CreateSessionRequest

use of com.google.spanner.v1.CreateSessionRequest in project java-spanner by googleapis.

the class GapicSpannerRpc method createSession.

@Override
public Session createSession(String databaseName, @Nullable Map<String, String> labels, @Nullable Map<Option, ?> options) throws SpannerException {
    CreateSessionRequest.Builder requestBuilder = CreateSessionRequest.newBuilder().setDatabase(databaseName);
    if (labels != null && !labels.isEmpty()) {
        Session.Builder session = Session.newBuilder().putAllLabels(labels);
        requestBuilder.setSession(session);
    }
    CreateSessionRequest request = requestBuilder.build();
    GrpcCallContext context = newCallContext(options, databaseName, request, SpannerGrpc.getCreateSessionMethod());
    return get(spannerStub.createSessionCallable().futureCall(request, context));
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Session(com.google.spanner.v1.Session)

Example 13 with CreateSessionRequest

use of com.google.spanner.v1.CreateSessionRequest in project java-spanner by googleapis.

the class MockSpannerServiceImpl method createSession.

@Override
public void createSession(CreateSessionRequest request, StreamObserver<Session> responseObserver) {
    requests.add(request);
    Preconditions.checkNotNull(request.getDatabase());
    String name = generateSessionName(request.getDatabase());
    try {
        createSessionExecutionTime.simulateExecutionTime(exceptions, stickyGlobalExceptions, freezeLock);
        Timestamp now = getCurrentGoogleTimestamp();
        Session session = Session.newBuilder().setCreateTime(now).setName(name).setApproximateLastUseTime(now).build();
        Session prev = sessions.putIfAbsent(name, session);
        if (prev == null) {
            sessionLastUsed.put(name, Instant.now());
            numSessionsCreated.incrementAndGet();
            responseObserver.onNext(session);
            responseObserver.onCompleted();
        } else {
            // Someone else tried to create a session with the same id. This should not be possible
            responseObserver.onError(Status.ALREADY_EXISTS.asRuntimeException());
        }
    } catch (StatusRuntimeException e) {
        sessions.remove(name);
        responseObserver.onError(e);
    } catch (Throwable e) {
        sessions.remove(name);
        responseObserver.onError(Status.INTERNAL.withDescription("Create session failed: " + e.getMessage()).asRuntimeException());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ByteString(com.google.protobuf.ByteString) Timestamp(com.google.protobuf.Timestamp) Session(com.google.spanner.v1.Session)

Example 14 with CreateSessionRequest

use of com.google.spanner.v1.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method testCreateAndGetSessionBlocking.

@Test
public void testCreateAndGetSessionBlocking() throws Exception {
    SpannerBlockingStub stub = getSpannerBlockingStub();
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
    // The first MAX_CHANNEL requests (without affinity) should be distributed 1 per channel.
    List<Session> sessions = new ArrayList<>();
    for (int i = 0; i < MAX_CHANNEL; i++) {
        Session session = stub.createSession(req);
        assertThat(session).isNotEqualTo(null);
        sessions.add(session);
        Session responseGet = stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).build());
        assertEquals(responseGet.getName(), session.getName());
    }
    checkChannelRefs(MAX_CHANNEL, 0, 1);
    for (Session session : sessions) {
        deleteSession(stub, session);
    }
    checkChannelRefs(MAX_CHANNEL, 0, 0);
}
Also used : CreateSessionRequest(com.google.spanner.v1.CreateSessionRequest) SpannerBlockingStub(com.google.spanner.v1.SpannerGrpc.SpannerBlockingStub) ArrayList(java.util.ArrayList) Session(com.google.spanner.v1.Session) Test(org.junit.Test)

Example 15 with CreateSessionRequest

use of com.google.spanner.v1.CreateSessionRequest in project grpc-gcp-java by GoogleCloudPlatform.

the class SpannerIntegrationTest method testBoundAfterUnbind.

@Test
public void testBoundAfterUnbind() {
    SpannerBlockingStub stub = getSpannerBlockingStub();
    CreateSessionRequest req = CreateSessionRequest.newBuilder().setDatabase(DATABASE_PATH).build();
    Session session = stub.createSession(req);
    stub.deleteSession(DeleteSessionRequest.newBuilder().setName(session.getName()).build());
    expectedEx.expect(StatusRuntimeException.class);
    expectedEx.expectMessage("NOT_FOUND: Session not found: " + session.getName());
    stub.getSession(GetSessionRequest.newBuilder().setName(session.getName()).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)

Aggregations

Session (com.google.spanner.v1.Session)12 CreateSessionRequest (com.google.spanner.v1.CreateSessionRequest)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 ByteString (com.google.protobuf.ByteString)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