Search in sources :

Example 16 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class MasterClient214 method commit.

@Override
public Response<Long> commit(RequestContext context, TransactionRepresentation tx) {
    Serializer serializer = new Protocol.TransactionSerializer(tx);
    Deserializer<Long> deserializer = (buffer, temporaryBuffer) -> buffer.readLong();
    return sendRequest(requestTypes.type(HaRequestTypes.Type.COMMIT), context, serializer, deserializer);
}
Also used : VOID_DESERIALIZER(org.neo4j.com.Protocol.VOID_DESERIALIZER) StoreId(org.neo4j.kernel.impl.store.StoreId) IdAllocation(org.neo4j.kernel.ha.id.IdAllocation) RequestType(org.neo4j.com.RequestType) LockResult(org.neo4j.kernel.ha.lock.LockResult) ObjectSerializer(org.neo4j.com.ObjectSerializer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) ResourceType(org.neo4j.storageengine.api.lock.ResourceType) Exceptions(org.neo4j.helpers.Exceptions) StoreWriter(org.neo4j.com.storecopy.StoreWriter) LogProvider(org.neo4j.logging.LogProvider) Serializer(org.neo4j.com.Serializer) HandshakeResult(org.neo4j.kernel.ha.com.master.HandshakeResult) IdRange(org.neo4j.kernel.impl.store.id.IdRange) RequestContext(org.neo4j.com.RequestContext) RequestMonitor(org.neo4j.com.monitor.RequestMonitor) ReadableClosablePositionAwareChannel(org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel) INTERNAL_PROTOCOL_VERSION(org.neo4j.com.ProtocolVersion.INTERNAL_PROTOCOL_VERSION) MasterClient(org.neo4j.kernel.ha.com.slave.MasterClient) ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) Client(org.neo4j.com.Client) EMPTY_SERIALIZER(org.neo4j.com.Protocol.EMPTY_SERIALIZER) Response(org.neo4j.com.Response) Protocol(org.neo4j.com.Protocol) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) LogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader) IOException(java.io.IOException) Protocol214(org.neo4j.com.Protocol214) MasterServer(org.neo4j.kernel.ha.com.master.MasterServer) LockStatus(org.neo4j.kernel.ha.lock.LockStatus) String.format(java.lang.String.format) IdType(org.neo4j.kernel.impl.store.id.IdType) ResponseUnpacker(org.neo4j.com.storecopy.ResponseUnpacker) Protocol.writeString(org.neo4j.com.Protocol.writeString) ProtocolVersion(org.neo4j.com.ProtocolVersion) Protocol.readString(org.neo4j.com.Protocol.readString) Deserializer(org.neo4j.com.Deserializer) Master(org.neo4j.kernel.ha.com.master.Master) ObjectSerializer(org.neo4j.com.ObjectSerializer) Serializer(org.neo4j.com.Serializer)

Example 17 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class SlaveTransactionCommitProcess method commit.

@Override
public long commit(TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode) throws TransactionFailureException {
    if (batch.next() != null) {
        throw new IllegalArgumentException("Only supports single-commit on slave --> master");
    }
    try {
        TransactionRepresentation representation = batch.transactionRepresentation();
        RequestContext context = requestContextFactory.newRequestContext(representation.getLockSessionId());
        try (Response<Long> response = master.commit(context, representation)) {
            return response.response();
        }
    } catch (IOException e) {
        throw new TransactionFailureException(Status.Transaction.TransactionCommitFailed, e, "Could not commit transaction on the master");
    } catch (ComException e) {
        throw new TransientTransactionFailureException("Cannot commit this transaction on the master. " + "The master is either down, or we have network connectivity problems.", e);
    }
}
Also used : ComException(org.neo4j.com.ComException) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) TransactionFailureException(org.neo4j.kernel.api.exceptions.TransactionFailureException) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) TransientTransactionFailureException(org.neo4j.graphdb.TransientTransactionFailureException) RequestContext(org.neo4j.com.RequestContext) IOException(java.io.IOException)

Example 18 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class SlaveUpdatePullerTest method setUp.

@Before
public void setUp() throws Throwable {
    when(requestContextFactory.newRequestContext()).thenReturn(new RequestContext(42, 42, 42, 42, 42));
    when(config.get(HaSettings.pull_interval)).thenReturn(1000L);
    when(config.get(ClusterSettings.server_id)).thenReturn(instanceId);
    when(availabilityGuard.isAvailable(anyLong())).thenReturn(true);
    jobScheduler.init();
    jobScheduler.start();
    updatePuller.start();
}
Also used : RequestContext(org.neo4j.com.RequestContext) Before(org.junit.Before)

Example 19 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class ConversationManagerTest method testConversationWorkflow.

@Test
public void testConversationWorkflow() throws Exception {
    JobScheduler.JobHandle reaperJobHandle = mock(JobScheduler.JobHandle.class);
    when(config.get(HaSettings.lock_read_timeout)).thenReturn(1L);
    when(conversationSPI.scheduleRecurringJob(any(JobScheduler.Group.class), any(Long.class), any(Runnable.class))).thenReturn(reaperJobHandle);
    RequestContext requestContext = getRequestContext();
    conversationManager = getConversationManager();
    TimedRepository conversationStorage = mock(TimedRepository.class);
    conversationManager.conversations = conversationStorage;
    conversationManager.begin(requestContext);
    conversationManager.acquire(requestContext);
    conversationManager.release(requestContext);
    conversationManager.end(requestContext);
    InOrder conversationOrder = inOrder(conversationStorage);
    conversationOrder.verify(conversationStorage).begin(requestContext);
    conversationOrder.verify(conversationStorage).acquire(requestContext);
    conversationOrder.verify(conversationStorage).release(requestContext);
    conversationOrder.verify(conversationStorage).end(requestContext);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) InOrder(org.mockito.InOrder) TimedRepository(org.neo4j.kernel.impl.util.collection.TimedRepository) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 20 with RequestContext

use of org.neo4j.com.RequestContext in project neo4j by neo4j.

the class ConversationManagerTest method testConversationStop.

@Test
public void testConversationStop() {
    RequestContext requestContext = getRequestContext();
    conversationManager = getConversationManager();
    Conversation conversation = mock(Conversation.class);
    when(conversation.isActive()).thenReturn(true);
    TimedRepository conversationStorage = mock(TimedRepository.class);
    when(conversationStorage.end(requestContext)).thenReturn(conversation);
    conversationManager.conversations = conversationStorage;
    conversationManager.stop(requestContext);
    verify(conversationStorage).end(requestContext);
    verify(conversation).stop();
}
Also used : TimedRepository(org.neo4j.kernel.impl.util.collection.TimedRepository) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Aggregations

RequestContext (org.neo4j.com.RequestContext)38 Test (org.junit.Test)21 Config (org.neo4j.kernel.configuration.Config)13 SPI (org.neo4j.kernel.ha.com.master.MasterImpl.SPI)12 Response (org.neo4j.com.Response)10 LockResult (org.neo4j.kernel.ha.lock.LockResult)10 StoreId (org.neo4j.kernel.impl.store.StoreId)9 IOException (java.io.IOException)8 StoreWriter (org.neo4j.com.storecopy.StoreWriter)8 DefaultConversationSPI (org.neo4j.kernel.ha.cluster.DefaultConversationSPI)8 MasterClient (org.neo4j.kernel.ha.com.slave.MasterClient)8 Client (org.neo4j.kernel.impl.locking.Locks.Client)8 TransactionRepresentation (org.neo4j.kernel.impl.transaction.TransactionRepresentation)8 ResponseUnpacker (org.neo4j.com.storecopy.ResponseUnpacker)7 HandshakeResult (org.neo4j.kernel.ha.com.master.HandshakeResult)7 Master (org.neo4j.kernel.ha.com.master.Master)7 RequestMonitor (org.neo4j.com.monitor.RequestMonitor)6 ReadableClosablePositionAwareChannel (org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel)6 String.format (java.lang.String.format)5 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4