use of org.hamcrest.Description in project platform_frameworks_base by android.
the class MockUtils method checkUserRestrictions.
public static Bundle checkUserRestrictions(String... keys) {
final Bundle expected = DpmTestUtils.newRestrictions(Preconditions.checkNotNull(keys));
final Matcher<Bundle> m = new BaseMatcher<Bundle>() {
@Override
public boolean matches(Object item) {
if (item == null)
return false;
return UserRestrictionsUtils.areEqual((Bundle) item, expected);
}
@Override
public void describeTo(Description description) {
description.appendText("User restrictions=" + getRestrictionsAsString(expected));
}
};
return MockitoHamcrest.argThat(m);
}
use of org.hamcrest.Description in project flink by apache.
the class CheckpointStateRestoreTest method testSetState.
/**
* Tests that on restore the task state is reset for each stateful task.
*/
@Test
public void testSetState() {
try {
final ChainedStateHandle<StreamStateHandle> serializedState = CheckpointCoordinatorTest.generateChainedStateHandle(new SerializableObject());
KeyGroupRange keyGroupRange = KeyGroupRange.of(0, 0);
List<SerializableObject> testStates = Collections.singletonList(new SerializableObject());
final KeyGroupsStateHandle serializedKeyGroupStates = CheckpointCoordinatorTest.generateKeyGroupState(keyGroupRange, testStates);
final JobID jid = new JobID();
final JobVertexID statefulId = new JobVertexID();
final JobVertexID statelessId = new JobVertexID();
Execution statefulExec1 = mockExecution();
Execution statefulExec2 = mockExecution();
Execution statefulExec3 = mockExecution();
Execution statelessExec1 = mockExecution();
Execution statelessExec2 = mockExecution();
ExecutionVertex stateful1 = mockExecutionVertex(statefulExec1, statefulId, 0, 3);
ExecutionVertex stateful2 = mockExecutionVertex(statefulExec2, statefulId, 1, 3);
ExecutionVertex stateful3 = mockExecutionVertex(statefulExec3, statefulId, 2, 3);
ExecutionVertex stateless1 = mockExecutionVertex(statelessExec1, statelessId, 0, 2);
ExecutionVertex stateless2 = mockExecutionVertex(statelessExec2, statelessId, 1, 2);
ExecutionJobVertex stateful = mockExecutionJobVertex(statefulId, new ExecutionVertex[] { stateful1, stateful2, stateful3 });
ExecutionJobVertex stateless = mockExecutionJobVertex(statelessId, new ExecutionVertex[] { stateless1, stateless2 });
Map<JobVertexID, ExecutionJobVertex> map = new HashMap<JobVertexID, ExecutionJobVertex>();
map.put(statefulId, stateful);
map.put(statelessId, stateless);
CheckpointCoordinator coord = new CheckpointCoordinator(jid, 200000L, 200000L, 0, Integer.MAX_VALUE, ExternalizedCheckpointSettings.none(), new ExecutionVertex[] { stateful1, stateful2, stateful3, stateless1, stateless2 }, new ExecutionVertex[] { stateful1, stateful2, stateful3, stateless1, stateless2 }, new ExecutionVertex[0], new StandaloneCheckpointIDCounter(), new StandaloneCompletedCheckpointStore(1), null, Executors.directExecutor());
// create ourselves a checkpoint with state
final long timestamp = 34623786L;
coord.triggerCheckpoint(timestamp, false);
PendingCheckpoint pending = coord.getPendingCheckpoints().values().iterator().next();
final long checkpointId = pending.getCheckpointId();
SubtaskState checkpointStateHandles = new SubtaskState(serializedState, null, null, serializedKeyGroupStates, null);
coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statefulExec1.getAttemptId(), checkpointId, new CheckpointMetrics(), checkpointStateHandles));
coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statefulExec2.getAttemptId(), checkpointId, new CheckpointMetrics(), checkpointStateHandles));
coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statefulExec3.getAttemptId(), checkpointId, new CheckpointMetrics(), checkpointStateHandles));
coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statelessExec1.getAttemptId(), checkpointId));
coord.receiveAcknowledgeMessage(new AcknowledgeCheckpoint(jid, statelessExec2.getAttemptId(), checkpointId));
assertEquals(1, coord.getNumberOfRetainedSuccessfulCheckpoints());
assertEquals(0, coord.getNumberOfPendingCheckpoints());
// let the coordinator inject the state
coord.restoreLatestCheckpointedState(map, true, false);
// verify that each stateful vertex got the state
final TaskStateHandles taskStateHandles = new TaskStateHandles(serializedState, Collections.<Collection<OperatorStateHandle>>singletonList(null), Collections.<Collection<OperatorStateHandle>>singletonList(null), Collections.singletonList(serializedKeyGroupStates), null);
BaseMatcher<TaskStateHandles> matcher = new BaseMatcher<TaskStateHandles>() {
@Override
public boolean matches(Object o) {
if (o instanceof TaskStateHandles) {
return o.equals(taskStateHandles);
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendValue(taskStateHandles);
}
};
verify(statefulExec1, times(1)).setInitialState(Mockito.argThat(matcher));
verify(statefulExec2, times(1)).setInitialState(Mockito.argThat(matcher));
verify(statefulExec3, times(1)).setInitialState(Mockito.argThat(matcher));
verify(statelessExec1, times(0)).setInitialState(Mockito.<TaskStateHandles>any());
verify(statelessExec2, times(0)).setInitialState(Mockito.<TaskStateHandles>any());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.hamcrest.Description in project freud by LMAX-Exchange.
the class ClassByteCodeMethodMatchers method hasMethodInvocation.
public static FreudExtendedMatcher<ClassByteCodeMethod> hasMethodInvocation(final Class expectedOwner, final String expectedMethodName, final Class... expectedParamsDeclared) {
return new FreudExtendedMatcher<ClassByteCodeMethod>() {
private String expectedOwnerName;
private String[] expectedParamNames;
{
expectedOwnerName = typeEncoding(expectedOwner);
expectedParamNames = (expectedParamsDeclared.length == 0) ? EMPTY_ARGS : new String[expectedParamsDeclared.length];
for (int i = 0, size = expectedParamsDeclared.length; i < size; i++) {
expectedParamNames[i] = typeEncoding(expectedParamsDeclared[i]);
}
}
@Override
protected boolean matchesSafely(final ClassByteCodeMethod item) {
final boolean[] found = new boolean[] { false };
found[0] = false;
item.findInstruction(new AbstractInstructionVisitor() {
@Override
public void methodInvocation(final Instruction instruction, final String owner, final String methodName, final String... args) {
if (!found[0] && expectedOwnerName.equals(owner) && expectedMethodName.equals(methodName) && Arrays.equals(expectedParamNames, args)) {
found[0] = true;
}
}
});
return found[0];
}
@Override
public void describeTo(final Description description) {
description.appendText("hasMethodInvocation(" + expectedOwner.getName() + ", " + expectedMethodName + ", " + Arrays.toString(expectedParamNames) + ")");
}
};
}
use of org.hamcrest.Description in project freud by LMAX-Exchange.
the class CodeBlockMatchers method hasMethodCall.
public static FreudExtendedMatcher<CodeBlock> hasMethodCall(final String methodCall) {
return new FreudExtendedMatcher<CodeBlock>() {
private final String methodName;
private final String[] instanceReferences;
{
String[] values = methodCall.split("\\.");
instanceReferences = new String[values.length - 1];
System.arraycopy(values, 0, instanceReferences, 0, instanceReferences.length);
methodName = values[values.length - 1];
}
@Override
protected boolean matchesSafely(final CodeBlock toBeAnalysed) {
List<MethodCall> methodCallList = toBeAnalysed.getMethodCallListByMethodName(methodName);
if (methodCallList != null) {
for (MethodCall methodCall : methodCallList) {
if (Arrays.equals(instanceReferences, methodCall.getInstanceReferences())) {
return true;
}
}
}
return false;
}
@Override
public void describeTo(final Description description) {
description.appendText("HasMethodCall(" + methodCall + ")");
}
};
}
use of org.hamcrest.Description in project sonarqube by SonarSource.
the class ReportSubmitterTest method submit_a_report_on_existing_project.
@Test
public void submit_a_report_on_existing_project() {
ComponentDto project = db.components().insertProject(db.getDefaultOrganization());
userSession.logIn().addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
mockSuccessfulPrepareSubmitCall();
underTest.submit(defaultOrganizationKey, project.getKey(), null, project.name(), IOUtils.toInputStream("{binary}"));
verifyReportIsPersisted(TASK_UUID);
verifyZeroInteractions(permissionTemplateService);
verifyZeroInteractions(favoriteUpdater);
verify(queue).submit(argThat(new TypeSafeMatcher<CeTaskSubmit>() {
@Override
protected boolean matchesSafely(CeTaskSubmit submit) {
return submit.getType().equals(CeTaskTypes.REPORT) && submit.getComponentUuid().equals(project.uuid()) && submit.getUuid().equals(TASK_UUID);
}
@Override
public void describeTo(Description description) {
}
}));
}
Aggregations