Search in sources :

Example 11 with UnsignedLong

use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.

the class SimpleShardDataTreeCohortTest method testPreCommitAndCommitSuccess.

@Test
public void testPreCommitAndCommitSuccess() throws Exception {
    canCommitSuccess();
    final DataTreeCandidateTip candidate = preCommitSuccess();
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0), () -> {
        });
        return null;
    }).when(mockShardDataTree).startCommit(cohort, candidate);
    @SuppressWarnings("unchecked") final FutureCallback<UnsignedLong> mockCommitCallback = mock(FutureCallback.class);
    cohort.commit(mockCommitCallback);
    verify(mockCommitCallback).onSuccess(any(UnsignedLong.class));
    verifyNoMoreInteractions(mockCommitCallback);
    verify(mockUserCohorts).commit();
}
Also used : UnsignedLong(com.google.common.primitives.UnsignedLong) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip) Test(org.junit.Test)

Example 12 with UnsignedLong

use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.

the class FrontendShardDataTreeSnapshotMetadataTest method createFrontedClientMetadata.

private static FrontendClientMetadata createFrontedClientMetadata(final long num) {
    final String index = String.valueOf(num);
    final String indexName = "test_" + index;
    final FrontendIdentifier frontendIdentifier = FrontendIdentifier.create(MemberName.forName(indexName), FrontendType.forName(index));
    final ClientIdentifier clientIdentifier = ClientIdentifier.create(frontendIdentifier, num);
    final RangeSet<UnsignedLong> purgedHistories = TreeRangeSet.create();
    purgedHistories.add(Range.closed(UnsignedLong.ZERO, UnsignedLong.ONE));
    final Collection<FrontendHistoryMetadata> currentHistories = Collections.singleton(new FrontendHistoryMetadata(num, num, true, ImmutableMap.of(UnsignedLong.ZERO, Boolean.TRUE), purgedHistories));
    return new FrontendClientMetadata(clientIdentifier, purgedHistories, currentHistories);
}
Also used : ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) UnsignedLong(com.google.common.primitives.UnsignedLong) FrontendIdentifier(org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier)

Example 13 with UnsignedLong

use of com.google.common.primitives.UnsignedLong in project controller by opendaylight.

the class AbstractFrontendHistory method handleTransactionRequest.

@Nullable
final TransactionSuccess<?> handleTransactionRequest(final TransactionRequest<?> request, final RequestEnvelope envelope, final long now) throws RequestException {
    if (request instanceof TransactionPurgeRequest) {
        return handleTransactionPurgeRequest(request, envelope, now);
    }
    final TransactionIdentifier id = request.getTarget();
    final UnsignedLong ul = UnsignedLong.fromLongBits(id.getTransactionId());
    if (purgedTransactions.contains(ul)) {
        LOG.warn("{}: Request {} is contained purged transactions {}", persistenceId, request, purgedTransactions);
        throw new DeadTransactionException(purgedTransactions);
    }
    final Boolean closed = closedTransactions.get(ul);
    if (closed != null) {
        final boolean successful = closed.booleanValue();
        LOG.debug("{}: Request {} refers to a {} transaction", persistenceId, request, successful ? "successful" : "failed");
        throw new ClosedTransactionException(successful);
    }
    FrontendTransaction tx = transactions.get(id);
    if (tx == null) {
        // The transaction does not exist and we are about to create it, check sequence number
        if (request.getSequence() != 0) {
            LOG.warn("{}: no transaction state present, unexpected request {}", persistenceId(), request);
            throw new OutOfOrderRequestException(0);
        }
        tx = createTransaction(request, id);
        transactions.put(id, tx);
    } else if (!(request instanceof IncrementTransactionSequenceRequest)) {
        final Optional<TransactionSuccess<?>> maybeReplay = tx.replaySequence(request.getSequence());
        if (maybeReplay.isPresent()) {
            final TransactionSuccess<?> replay = maybeReplay.get();
            LOG.debug("{}: envelope {} replaying response {}", persistenceId(), envelope, replay);
            return replay;
        }
    }
    return tx.handleRequest(request, envelope, now);
}
Also used : TransactionSuccess(org.opendaylight.controller.cluster.access.commands.TransactionSuccess) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) UnsignedLong(com.google.common.primitives.UnsignedLong) Optional(java.util.Optional) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ClosedTransactionException(org.opendaylight.controller.cluster.access.commands.ClosedTransactionException) OutOfOrderRequestException(org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException) DeadTransactionException(org.opendaylight.controller.cluster.access.commands.DeadTransactionException) Nullable(javax.annotation.Nullable)

Example 14 with UnsignedLong

use of com.google.common.primitives.UnsignedLong in project symja_android_library by axkr.

the class NumericArrayExpr method arrayUnsignedLongRecursive.

private static boolean arrayUnsignedLongRecursive(IAST nestedListsOfValues, int level, long[] longArr, int[] index) throws RangeException, TypeException {
    level--;
    for (int i = 1; i < nestedListsOfValues.size(); i++) {
        IExpr arg = nestedListsOfValues.get(i);
        if (level == 0) {
            if (!arg.isInteger()) {
                throw new TypeException("Not a valid Integers type");
            }
            BigInteger value = ((IInteger) arg).toBigNumerator();
            UnsignedLong uint64 = UnsignedLong.valueOf(value);
            longArr[index[0]++] = uint64.longValue();
        } else {
            if (!arg.isList() || !arrayUnsignedLongRecursive((IAST) arg, level, longArr, index)) {
                return false;
            }
        }
    }
    return true;
}
Also used : UnsignedLong(com.google.common.primitives.UnsignedLong) IInteger(org.matheclipse.core.interfaces.IInteger) BigInteger(java.math.BigInteger) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException) IExpr(org.matheclipse.core.interfaces.IExpr)

Example 15 with UnsignedLong

use of com.google.common.primitives.UnsignedLong in project coprhd-controller by CoprHD.

the class NodeStatsExtractor method getCPUTimeDeltaMS.

/**
 * Returns the cpu time spent in MS. If interval is > 0 delta value is returned.
 * This is used to calculate per sec values.
 */
protected static double getCPUTimeDeltaMS(CPUStats oldCPUStats, CPUStats newCPUStats) {
    if (oldCPUStats != null) {
        double statsDiff;
        UnsignedLong oldTotal = oldCPUStats.getUserMode().plus(oldCPUStats.getSystemMode().plus(oldCPUStats.getIdle().plus(oldCPUStats.getIowait())));
        if (newCPUStats != null) {
            UnsignedLong newTotal = newCPUStats.getUserMode().plus(newCPUStats.getSystemMode().plus(newCPUStats.getIdle().plus(newCPUStats.getIowait())));
            statsDiff = newTotal.minus(oldTotal).doubleValue();
        } else {
            statsDiff = oldTotal.doubleValue();
        }
        return ProcStats.getCPUCount() > 0 ? 1000.0 * statsDiff / ProcStats.getCPUCount() / HZ : 0;
    } else {
        return 0;
    }
}
Also used : UnsignedLong(com.google.common.primitives.UnsignedLong)

Aggregations

UnsignedLong (com.google.common.primitives.UnsignedLong)21 Test (org.junit.Test)8 BigInteger (java.math.BigInteger)4 InOrder (org.mockito.InOrder)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)3 ArrayList (java.util.ArrayList)2 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 CommitTransactionPayload (org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload)2 DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)2 CPUStats (com.emc.storageos.systemservices.impl.healthmonitor.models.CPUStats)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)1 IExpr (org.matheclipse.core.interfaces.IExpr)1