Search in sources :

Example 1 with TransactionObligationResponse

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

the class SlaveLocksClientTest method shouldIncludeReasonForNotLocked.

@Test
public void shouldIncludeReasonForNotLocked() throws Exception {
    // GIVEN
    SlaveLocksClient client = newSlaveLocksClient(lockManager);
    LockResult lockResult = new LockResult(LockStatus.NOT_LOCKED, "Simply not locked");
    Response<LockResult> response = new TransactionObligationResponse<>(lockResult, DEFAULT, 2, NO_OP);
    long nodeId = 0;
    ResourceTypes resourceType = NODE;
    when(master.acquireExclusiveLock(any(RequestContext.class), eq(resourceType), anyLong())).thenReturn(response);
    // WHEN
    try {
        client.acquireExclusive(LockTracer.NONE, resourceType, nodeId);
        fail("Should have failed");
    } catch (UnsupportedOperationException e) {
        // THEN
        assertThat(e.getMessage(), containsString(lockResult.getMessage()));
        assertThat(e.getMessage(), containsString(lockResult.getStatus().name()));
    }
}
Also used : ResourceTypes(org.neo4j.kernel.impl.locking.ResourceTypes) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) RequestContext(org.neo4j.com.RequestContext) Test(org.junit.Test)

Example 2 with TransactionObligationResponse

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

the class ResponsePackerIT method shouldPackTheHighestTxCommittedAsObligation.

@Test
public void shouldPackTheHighestTxCommittedAsObligation() throws Exception {
    // GIVEN
    LogicalTransactionStore transactionStore = mock(LogicalTransactionStore.class);
    FileSystemAbstraction fs = fsRule.get();
    PageCache pageCache = pageCacheRule.getPageCache(fs);
    try (NeoStores neoStore = createNeoStore(fs, pageCache)) {
        MetaDataStore store = neoStore.getMetaDataStore();
        store.transactionCommitted(2, 111, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(3, 222, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(4, 333, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(5, 444, BASE_TX_COMMIT_TIMESTAMP);
        store.transactionCommitted(6, 555, BASE_TX_COMMIT_TIMESTAMP);
        // skip 7 to emulate the fact we have an hole in the committed tx ids list
        final long expectedTxId = 8L;
        store.transactionCommitted(expectedTxId, 777, BASE_TX_COMMIT_TIMESTAMP);
        ResponsePacker packer = new ResponsePacker(transactionStore, store, Suppliers.singleton(newStoreIdForCurrentVersion()));
        // WHEN
        Response<Object> response = packer.packTransactionObligationResponse(new RequestContext(0, 0, 0, 0, 0), new Object());
        // THEN
        assertTrue(response instanceof TransactionObligationResponse);
        ((TransactionObligationResponse) response).accept(new Response.Handler() {

            @Override
            public void obligation(long txId) throws IOException {
                assertEquals(expectedTxId, txId);
            }

            @Override
            public Visitor<CommittedTransactionRepresentation, Exception> transactions() {
                throw new UnsupportedOperationException("not expected");
            }
        });
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Visitor(org.neo4j.helpers.collection.Visitor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) IOException(java.io.IOException) Response(org.neo4j.com.Response) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) NeoStores(org.neo4j.kernel.impl.store.NeoStores) TransactionObligationResponse(org.neo4j.com.TransactionObligationResponse) RequestContext(org.neo4j.com.RequestContext) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 RequestContext (org.neo4j.com.RequestContext)2 TransactionObligationResponse (org.neo4j.com.TransactionObligationResponse)2 IOException (java.io.IOException)1 Response (org.neo4j.com.Response)1 Visitor (org.neo4j.helpers.collection.Visitor)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 PageCache (org.neo4j.io.pagecache.PageCache)1 ResourceTypes (org.neo4j.kernel.impl.locking.ResourceTypes)1 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)1