Search in sources :

Example 6 with RequestContext

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

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource.

@Test
public void lockResultMustHaveMessageWhenAcquiringExclusiveLockThrowsIllegalResource() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    conversationManager.start();
    Client locks = mock(Client.class);
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    ResourceTypes type = ResourceTypes.NODE;
    doThrow(new IllegalResourceException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireExclusiveLock(context, type, 1);
    ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
    verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
    assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) Test(org.junit.Test)

Example 7 with RequestContext

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

the class MasterImplTest method lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks.

@Test
public void lockResultMustHaveMessageWhenAcquiringSharedLockDeadlocks() throws Exception {
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    conversationManager.start();
    Client locks = mock(Client.class);
    MasterImpl master = new MasterImpl(spi, conversationManager, null, config);
    RequestContext context = createRequestContext(master);
    when(conversationSpi.acquireClient()).thenReturn(locks);
    ResourceTypes type = ResourceTypes.NODE;
    doThrow(new DeadlockDetectedException("")).when(locks).acquireExclusive(LockTracer.NONE, type, 1);
    master.acquireSharedLock(context, type, 1);
    ArgumentCaptor<LockResult> captor = ArgumentCaptor.forClass(LockResult.class);
    verify(spi).packTransactionObligationResponse(argThat(is(context)), captor.capture());
    assertThat(captor.getValue().getMessage(), is(not(nullValue())));
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) LockResult(org.neo4j.kernel.ha.lock.LockResult) Config(org.neo4j.kernel.configuration.Config) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) RequestContext(org.neo4j.com.RequestContext) Client(org.neo4j.kernel.impl.locking.Locks.Client) Test(org.junit.Test)

Example 8 with RequestContext

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

the class MasterImplTest method failingToStartTxShouldNotLeadToNPE.

@Test
public void failingToStartTxShouldNotLeadToNPE() throws Throwable {
    // Given
    MasterImpl.SPI spi = mockedSpi();
    DefaultConversationSPI conversationSpi = mockedConversationSpi();
    Config config = config();
    ConversationManager conversationManager = new ConversationManager(conversationSpi, config);
    when(spi.isAccessible()).thenReturn(true);
    when(conversationSpi.acquireClient()).thenThrow(new RuntimeException("Nope"));
    when(spi.getTransactionChecksum(anyLong())).thenReturn(1L);
    mockEmptyResponse(spi);
    MasterImpl instance = new MasterImpl(spi, conversationManager, mock(MasterImpl.Monitor.class), config);
    instance.start();
    Response<HandshakeResult> response = instance.handshake(1, newStoreIdForCurrentVersion());
    HandshakeResult handshake = response.response();
    // When
    try {
        instance.newLockSession(new RequestContext(handshake.epoch(), 1, 2, 0, 0));
        fail("Should have failed.");
    } catch (Exception e) {
        // Then
        assertThat(e, instanceOf(RuntimeException.class));
        assertThat(e.getMessage(), equalTo("Nope"));
    }
}
Also used : SPI(org.neo4j.kernel.ha.com.master.MasterImpl.SPI) DefaultConversationSPI(org.neo4j.kernel.ha.cluster.DefaultConversationSPI) Monitor(org.neo4j.kernel.ha.com.master.MasterImpl.Monitor) Config(org.neo4j.kernel.configuration.Config) RequestContext(org.neo4j.com.RequestContext) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) IllegalResourceException(org.neo4j.kernel.impl.transaction.IllegalResourceException) TransactionNotPresentOnMasterException(org.neo4j.com.TransactionNotPresentOnMasterException) NoSuchEntryException(org.neo4j.kernel.impl.util.collection.NoSuchEntryException) Test(org.junit.Test)

Example 9 with RequestContext

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

the class SlaveTransactionCommitProcessTest method setUp.

@Before
public void setUp() {
    lastSeenEventIdentifier = new AtomicInteger(-1);
    master = mock(Master.class);
    requestContext = new RequestContext(10, 11, 12, 13, 14);
    reqFactory = new ConstantRequestContextFactory(requestContext) {

        @Override
        public RequestContext newRequestContext(int eventIdentifier) {
            lastSeenEventIdentifier.set(eventIdentifier);
            return super.newRequestContext(eventIdentifier);
        }
    };
    response = new LongResponse(42L);
    tx = new PhysicalTransactionRepresentation(Collections.<StorageCommand>emptyList());
    tx.setHeader(new byte[] {}, 1, 1, 1, 1, 1, 1337);
    commitProcess = new SlaveTransactionCommitProcess(master, reqFactory);
}
Also used : Master(org.neo4j.kernel.ha.com.master.Master) LongResponse(org.neo4j.test.LongResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StorageCommand(org.neo4j.storageengine.api.StorageCommand) ConstantRequestContextFactory(org.neo4j.test.ConstantRequestContextFactory) RequestContext(org.neo4j.com.RequestContext) PhysicalTransactionRepresentation(org.neo4j.kernel.impl.transaction.log.PhysicalTransactionRepresentation) Before(org.junit.Before)

Example 10 with RequestContext

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

the class StoreCopyResponsePacker method packTransactionStreamResponse.

@Override
public <T> Response<T> packTransactionStreamResponse(RequestContext context, T response) {
    final long toStartFrom = mandatoryStartTransactionId;
    final long toEndAt = transactionIdStore.getLastCommittedTransactionId();
    TransactionStream transactions = visitor -> {
        if (toStartFrom > BASE_TX_ID && toStartFrom <= toEndAt) {
            monitor.startStreamingTransactions(toStartFrom);
            extractTransactions(toStartFrom, filterVisitor(visitor, toEndAt));
            monitor.finishStreamingTransactions(toEndAt);
        }
    };
    return new TransactionStreamResponse<>(response, storeId.get(), transactions, ResourceReleaser.NO_OP);
}
Also used : Response(org.neo4j.com.Response) StoreId(org.neo4j.kernel.impl.store.StoreId) TransactionStream(org.neo4j.com.TransactionStream) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) NoSuchTransactionException(org.neo4j.kernel.impl.transaction.log.NoSuchTransactionException) Supplier(java.util.function.Supplier) RequestContext(org.neo4j.com.RequestContext) TransactionStreamResponse(org.neo4j.com.TransactionStreamResponse) ResponsePacker(org.neo4j.com.storecopy.ResponsePacker) CommittedTransactionRepresentation(org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation) LogFileInformation(org.neo4j.kernel.impl.transaction.log.LogFileInformation) Monitor(org.neo4j.com.storecopy.StoreCopyServer.Monitor) StoreCopyServer(org.neo4j.com.storecopy.StoreCopyServer) ResourceReleaser(org.neo4j.com.ResourceReleaser) Visitor(org.neo4j.helpers.collection.Visitor) BASE_TX_ID(org.neo4j.kernel.impl.transaction.log.TransactionIdStore.BASE_TX_ID) TransactionStreamResponse(org.neo4j.com.TransactionStreamResponse) TransactionStream(org.neo4j.com.TransactionStream)

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