Search in sources :

Example 1 with TransactionCallbackWithoutResult

use of org.openkilda.persistence.tx.TransactionCallbackWithoutResult in project open-kilda by telstra.

the class NetworkIslServiceTest method setUp.

@Before
public void setUp() {
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
    when(repositoryFactory.createIslRepository()).thenReturn(islRepository);
    when(repositoryFactory.createLinkPropsRepository()).thenReturn(linkPropsRepository);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createFeatureTogglesRepository()).thenReturn(featureTogglesRepository);
    when(repositoryFactory.createSwitchPropertiesRepository()).thenReturn(switchPropertiesRepository);
    KildaFeatureToggles featureToggles = new KildaFeatureToggles(KildaFeatureToggles.DEFAULTS);
    featureToggles.setFlowsRerouteOnIslDiscoveryEnabled(true);
    when(featureTogglesRepository.getOrDefault()).thenReturn(featureToggles);
    when(transactionManager.getDefaultRetryPolicy()).thenReturn(new RetryPolicy<>().withMaxRetries(2));
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult<?> tr = invocation.getArgument(0);
        tr.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(Mockito.any(TransactionCallbackWithoutResult.class));
    doAnswer(invocation -> {
        RetryPolicy<?> retryPolicy = invocation.getArgument(0);
        TransactionCallbackWithoutResult<?> tr = invocation.getArgument(1);
        Failsafe.with(retryPolicy).run(tr::doInTransaction);
        return null;
    }).when(transactionManager).doInTransaction(Mockito.any(RetryPolicy.class), Mockito.any(TransactionCallbackWithoutResult.class));
    NetworkTopologyDashboardLogger.Builder dashboardLoggerBuilder = mock(NetworkTopologyDashboardLogger.Builder.class);
    when(dashboardLoggerBuilder.build(any())).thenReturn(dashboardLogger);
    service = new NetworkIslService(carrier, persistenceManager, options, dashboardLoggerBuilder, clock);
}
Also used : KildaFeatureToggles(org.openkilda.model.KildaFeatureToggles) NetworkTopologyDashboardLogger(org.openkilda.wfm.topology.network.NetworkTopologyDashboardLogger) RetryPolicy(net.jodah.failsafe.RetryPolicy) TransactionCallbackWithoutResult(org.openkilda.persistence.tx.TransactionCallbackWithoutResult) Before(org.junit.Before)

Example 2 with TransactionCallbackWithoutResult

use of org.openkilda.persistence.tx.TransactionCallbackWithoutResult in project open-kilda by telstra.

the class NetworkBfdSessionServiceTest method setUp.

@Before
public void setUp() throws Exception {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
    when(repositoryFactory.createBfdSessionRepository()).thenReturn(bfdSessionRepository);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult<?> tr = invocation.getArgument(0);
        tr.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(Mockito.any(TransactionCallbackWithoutResult.class));
    doAnswer(invocation -> {
        TransactionCallback<?, ?> tr = invocation.getArgument(0);
        return tr.doInTransaction();
    }).when(transactionManager).doInTransaction(Mockito.any(TransactionCallback.class));
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    switchOnlineStatusMonitor = new SwitchOnlineStatusMonitor();
    endpointStatusMonitor = new EndpointStatusMonitor();
    setupCarrier();
    service = new NetworkBfdSessionService(persistenceManager, switchOnlineStatusMonitor, endpointStatusMonitor, carrier);
}
Also used : TransactionCallback(org.openkilda.persistence.tx.TransactionCallback) SwitchOnlineStatusMonitor(org.openkilda.wfm.topology.network.utils.SwitchOnlineStatusMonitor) EndpointStatusMonitor(org.openkilda.wfm.topology.network.utils.EndpointStatusMonitor) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) TransactionCallbackWithoutResult(org.openkilda.persistence.tx.TransactionCallbackWithoutResult) Before(org.junit.Before)

Example 3 with TransactionCallbackWithoutResult

use of org.openkilda.persistence.tx.TransactionCallbackWithoutResult in project open-kilda by telstra.

the class NetworkPortServiceTest method resetMocks.

private void resetMocks() {
    reset(carrier);
    reset(dashboardLogger);
    reset(persistenceManager);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    when(persistenceManager.getTransactionManager()).thenReturn(transactionManager);
    doAnswer(invocation -> {
        TransactionCallbackWithoutResult tr = invocation.getArgument(0);
        tr.doInTransaction();
        return null;
    }).when(transactionManager).doInTransaction(any(TransactionCallbackWithoutResult.class));
    reset(portPropertiesRepository);
    doAnswer(invocation -> invocation.getArgument(0)).when(portPropertiesRepository).add(any());
    reset(switchRepository);
    reset(repositoryFactory);
    when(repositoryFactory.createPortPropertiesRepository()).thenReturn(portPropertiesRepository);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
}
Also used : TransactionCallbackWithoutResult(org.openkilda.persistence.tx.TransactionCallbackWithoutResult)

Aggregations

TransactionCallbackWithoutResult (org.openkilda.persistence.tx.TransactionCallbackWithoutResult)3 Before (org.junit.Before)2 RetryPolicy (net.jodah.failsafe.RetryPolicy)1 KildaFeatureToggles (org.openkilda.model.KildaFeatureToggles)1 RepositoryFactory (org.openkilda.persistence.repositories.RepositoryFactory)1 TransactionCallback (org.openkilda.persistence.tx.TransactionCallback)1 NetworkTopologyDashboardLogger (org.openkilda.wfm.topology.network.NetworkTopologyDashboardLogger)1 EndpointStatusMonitor (org.openkilda.wfm.topology.network.utils.EndpointStatusMonitor)1 SwitchOnlineStatusMonitor (org.openkilda.wfm.topology.network.utils.SwitchOnlineStatusMonitor)1