use of java.util.Collections.emptyList in project n4js by eclipse.
the class ScriptApiTracker method _computeMissingApiGetterSetter.
/**
* Internal algorithm.
*/
private List<AccessorTuple> _computeMissingApiGetterSetter(TN4Classifier declaration, List<AccessorTuple> concreteAccessorTuples, Predicate<ProjectComparisonEntry> filterPredicate, boolean recursive) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(declaration, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration);
if (typeCompare == null) {
return Collections.emptyList();
}
Predicate<ProjectComparisonEntry> filter = (pce -> (pce.getElementAPI() instanceof TGetter) || (pce.getElementAPI() instanceof TSetter));
filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(filterPredicate);
ArrayList<ProjectComparisonEntry> collectedPCEofGetterOrSetter = new ArrayList<>();
Function<TN4Classifier, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
// Get or Set ??
collectedPCEofGetterOrSetter.add(pce);
};
// recursive Extension will generate a stream of compareEntries.
if (recursive)
interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TN4Classifier) typeCompare.getElementAPI(), TN4Classifier.class);
// ----
/*-
Cases of the Implementation: A getter or setter can
- be given as AST (x)
- be missing (m)
- were not required by API (/)
So we have 3*3=9 cases:
get set
(x) (x) --> all fine, pair will be transpiled
(x) (m) --> code for getter will be transpiled, need to inject virtual setter code into existing tuple.
(x) (/) --> all fine, getter will be transpiled
(m) (x) --> code for setter will be transpiled, need to inject virtual getter code into existing tuple.
(m) (m) --> need to create virtual accessor tuple (similar to missing field) with setter & getter
(m) (/) --> need to create virtual accessor tuple with getter only
(/) (x) --> all fine
(/) (m) --> need to create virtual accessor tuple with setter only
(/) (/) --> all fine nothing to be done.
*/
List<ProjectComparisonEntry> getSetList;
if (recursive)
getSetList = collectedPCEofGetterOrSetter;
else
getSetList = typeCompare.allChildren().filter(pce -> (pce.getElementAPI() instanceof TGetter) || (pce.getElementAPI() instanceof TSetter)).filter(filterPredicate).collect(Collectors.toList());
HashMap<Pair<String, Boolean>, GetSetGroup> hmName2getset = new HashMap<>();
for (ProjectComparisonEntry pce : getSetList) {
TMember apiAsMember = ((TMember) pce.getElementAPI());
String name = apiAsMember.getName();
boolean staticCase = apiAsMember.isStatic();
Pair<String, Boolean> key = Pair.of(name, staticCase);
GetSetGroup group = hmName2getset.get(key);
if (group == null) {
group = new GetSetGroup(name, staticCase);
hmName2getset.put(key, group);
}
if (pce.getElementAPI() instanceof TGetter) {
// case getter:
TGetter apiGetter = (TGetter) pce.getElementAPI();
if (pce.getElementImpl(0) != null) {
// case (x) for getter-
group.getterIsInAST = true;
} else {
// case (m) for getter-
group.getterIsInAST = false;
group.getter = new VirtualApiTGetter(name, apiGetter);
}
} else if (pce.getElementAPI() instanceof TSetter) {
// case setter:
TSetter apiSetter = (TSetter) pce.getElementAPI();
if (pce.getElementImpl(0) != null) {
// case (x) for setter -
group.setterIsInAST = true;
} else {
// case (m) for setter:
group.setterIsInAST = false;
group.setter = new VirtualApiTSetter(name, apiSetter);
}
}
}
// go over the list of known AccessorTupels and enhance them by adding virtual things.
for (AccessorTuple conAccTupel : concreteAccessorTuples) {
GetSetGroup getset = hmName2getset.remove(Pair.of(conAccTupel.getName(), conAccTupel.isStatic()));
if (getset != null) {
// some missings found:
if (getset.hasGetter() && !getset.getterIsInAST && // could be mixed in by interface-default-impl different
conAccTupel.getGetter() == null) // to the intended API-path c.f. GHOLD-212
{
conAccTupel.setGetter(getset.getter);
}
if (getset.hasSetter() && !getset.setterIsInAST && // could be mixed in by interface-default-impl different
conAccTupel.getSetter() == null) // to the intended API-path c.f. GHOLD-212
{
conAccTupel.setSetter(getset.setter);
}
}
}
// remaining entries in hmName2getset need to translated into VirtualApiAccessors.
List<AccessorTuple> ret = new ArrayList<>();
for (GetSetGroup getset : hmName2getset.values()) {
VirtualApiAccessorTuple vAccessTupel = new VirtualApiAccessorTuple(getset.name, getset.staticCases);
if (getset.getter != null)
vAccessTupel.setGetter(getset.getter);
if (getset.setter != null)
vAccessTupel.setSetter(getset.setter);
ret.add(vAccessTupel);
}
return ret;
}
return emptyList();
}
use of java.util.Collections.emptyList in project component-runtime by Talend.
the class SuggestionServiceImpl method computeKeySuggestions.
@Override
public List<LookupElement> computeKeySuggestions(final Project project, final Module module, final String packageName, final List<String> containerElements, final String query) {
final JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
final PsiPackage pkg = javaPsiFacade.findPackage(packageName);
if (pkg == null) {
return Collections.emptyList();
}
final String defaultFamily = getFamilyFromPackageInfo(pkg, module);
return Stream.concat(of(pkg.getClasses()).flatMap(this::unwrapInnerClasses).filter(c -> AnnotationUtil.findAnnotation(c, PARTITION_MAPPER, PROCESSOR, EMITTER) != null).flatMap(clazz -> fromComponent(clazz, defaultFamily)), of(pkg.getClasses()).flatMap(this::unwrapInnerClasses).filter(c -> of(c.getAllFields()).anyMatch(f -> AnnotationUtil.findAnnotation(f, OPTION) != null)).flatMap(c -> fromConfiguration(defaultFamily, c.getName(), c))).filter(s -> containerElements.isEmpty() || !containerElements.contains(s.getKey())).filter(s -> query == null || query.isEmpty() || s.getKey().startsWith(query)).map(s -> s.newLookupElement(withPriority(s.getType()))).collect(toList());
}
use of java.util.Collections.emptyList in project flink by apache.
the class CheckpointCoordinatorRestoringTest method testJobGraphModificationsAreCheckedForInitialCheckpoint.
@Test
public void testJobGraphModificationsAreCheckedForInitialCheckpoint() throws Exception {
final JobVertexID jobVertexID = new JobVertexID();
ExecutionGraph graph = new CheckpointCoordinatorTestingUtils.CheckpointExecutionGraphBuilder().addJobVertex(jobVertexID, 1, 1).build();
CompletedCheckpointStore completedCheckpointStore = new EmbeddedCompletedCheckpointStore();
CompletedCheckpoint completedCheckpoint = new CompletedCheckpoint(graph.getJobID(), 2, System.currentTimeMillis(), System.currentTimeMillis() + 3000, Collections.emptyMap(), Collections.emptyList(), CheckpointProperties.forCheckpoint(CheckpointRetentionPolicy.NEVER_RETAIN_AFTER_TERMINATION), new TestCompletedCheckpointStorageLocation());
completedCheckpointStore.addCheckpointAndSubsumeOldestOne(completedCheckpoint, new CheckpointsCleaner(), () -> {
});
BooleanValue checked = new BooleanValue(false);
CheckpointCoordinator restoreCoordinator = new CheckpointCoordinatorBuilder().setExecutionGraph(graph).setCompletedCheckpointStore(completedCheckpointStore).setVertexFinishedStateCheckerFactory((vertices, states) -> new VertexFinishedStateChecker(vertices, states) {
@Override
public void validateOperatorsFinishedState() {
checked.set(true);
}
}).build();
restoreCoordinator.restoreInitialCheckpointIfPresent(new HashSet<>(graph.getAllVertices().values()));
assertTrue("The finished states should be checked when job is restored on startup", checked.get());
}
use of java.util.Collections.emptyList in project kafka by apache.
the class ConsumerCoordinatorTest method testMetadataRefreshDuringRebalance.
@Test
public void testMetadataRefreshDuringRebalance() {
final String consumerId = "leader";
final List<TopicPartition> owned = Collections.emptyList();
final List<TopicPartition> oldAssigned = singletonList(t1p);
subscriptions.subscribe(Pattern.compile(".*"), rebalanceListener);
client.updateMetadata(RequestTestUtils.metadataUpdateWith(1, singletonMap(topic1, 1)));
coordinator.maybeUpdateSubscriptionMetadata();
assertEquals(singleton(topic1), subscriptions.subscription());
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady(time.timer(Long.MAX_VALUE));
Map<String, List<String>> initialSubscription = singletonMap(consumerId, singletonList(topic1));
partitionAssignor.prepare(singletonMap(consumerId, oldAssigned));
// the metadata will be updated in flight with a new topic added
final List<String> updatedSubscription = Arrays.asList(topic1, topic2);
client.prepareResponse(joinGroupLeaderResponse(1, consumerId, initialSubscription, Errors.NONE));
client.prepareResponse(body -> {
final Map<String, Integer> updatedPartitions = new HashMap<>();
for (String topic : updatedSubscription) updatedPartitions.put(topic, 1);
client.updateMetadata(RequestTestUtils.metadataUpdateWith(1, updatedPartitions));
return true;
}, syncGroupResponse(oldAssigned, Errors.NONE));
coordinator.poll(time.timer(Long.MAX_VALUE));
// rejoin will only be set in the next poll call
assertFalse(coordinator.rejoinNeededOrPending());
assertEquals(singleton(topic1), subscriptions.subscription());
assertEquals(toSet(oldAssigned), subscriptions.assignedPartitions());
// nothing to be revoked and hence no callback triggered
assertEquals(0, rebalanceListener.revokedCount);
assertNull(rebalanceListener.revoked);
assertEquals(1, rebalanceListener.assignedCount);
assertEquals(getAdded(owned, oldAssigned), rebalanceListener.assigned);
List<TopicPartition> newAssigned = Arrays.asList(t1p, t2p);
final Map<String, List<String>> updatedSubscriptions = singletonMap(consumerId, Arrays.asList(topic1, topic2));
partitionAssignor.prepare(singletonMap(consumerId, newAssigned));
// we expect to see a second rebalance with the new-found topics
client.prepareResponse(body -> {
JoinGroupRequest join = (JoinGroupRequest) body;
Iterator<JoinGroupRequestData.JoinGroupRequestProtocol> protocolIterator = join.data().protocols().iterator();
assertTrue(protocolIterator.hasNext());
JoinGroupRequestData.JoinGroupRequestProtocol protocolMetadata = protocolIterator.next();
ByteBuffer metadata = ByteBuffer.wrap(protocolMetadata.metadata());
ConsumerPartitionAssignor.Subscription subscription = ConsumerProtocol.deserializeSubscription(metadata);
metadata.rewind();
return subscription.topics().containsAll(updatedSubscription);
}, joinGroupLeaderResponse(2, consumerId, updatedSubscriptions, Errors.NONE));
// update the metadata again back to topic1
client.prepareResponse(body -> {
client.updateMetadata(RequestTestUtils.metadataUpdateWith(1, singletonMap(topic1, 1)));
return true;
}, syncGroupResponse(newAssigned, Errors.NONE));
coordinator.poll(time.timer(Long.MAX_VALUE));
Collection<TopicPartition> revoked = getRevoked(oldAssigned, newAssigned);
int revokedCount = revoked.isEmpty() ? 0 : 1;
assertFalse(coordinator.rejoinNeededOrPending());
assertEquals(toSet(updatedSubscription), subscriptions.subscription());
assertEquals(toSet(newAssigned), subscriptions.assignedPartitions());
assertEquals(revokedCount, rebalanceListener.revokedCount);
assertEquals(revoked.isEmpty() ? null : revoked, rebalanceListener.revoked);
assertEquals(2, rebalanceListener.assignedCount);
assertEquals(getAdded(oldAssigned, newAssigned), rebalanceListener.assigned);
// we expect to see a third rebalance with the new-found topics
partitionAssignor.prepare(singletonMap(consumerId, oldAssigned));
client.prepareResponse(body -> {
JoinGroupRequest join = (JoinGroupRequest) body;
Iterator<JoinGroupRequestData.JoinGroupRequestProtocol> protocolIterator = join.data().protocols().iterator();
assertTrue(protocolIterator.hasNext());
JoinGroupRequestData.JoinGroupRequestProtocol protocolMetadata = protocolIterator.next();
ByteBuffer metadata = ByteBuffer.wrap(protocolMetadata.metadata());
ConsumerPartitionAssignor.Subscription subscription = ConsumerProtocol.deserializeSubscription(metadata);
metadata.rewind();
return subscription.topics().contains(topic1);
}, joinGroupLeaderResponse(3, consumerId, initialSubscription, Errors.NONE));
client.prepareResponse(syncGroupResponse(oldAssigned, Errors.NONE));
coordinator.poll(time.timer(Long.MAX_VALUE));
revoked = getRevoked(newAssigned, oldAssigned);
assertFalse(revoked.isEmpty());
revokedCount += 1;
Collection<TopicPartition> added = getAdded(newAssigned, oldAssigned);
assertFalse(coordinator.rejoinNeededOrPending());
assertEquals(singleton(topic1), subscriptions.subscription());
assertEquals(toSet(oldAssigned), subscriptions.assignedPartitions());
assertEquals(revokedCount, rebalanceListener.revokedCount);
assertEquals(revoked.isEmpty() ? null : revoked, rebalanceListener.revoked);
assertEquals(3, rebalanceListener.assignedCount);
assertEquals(added, rebalanceListener.assigned);
assertEquals(0, rebalanceListener.lostCount);
}
use of java.util.Collections.emptyList in project kafka by apache.
the class ConsumerCoordinatorTest method testPatternJoinGroupLeader.
@Test
public void testPatternJoinGroupLeader() {
final String consumerId = "leader";
final List<TopicPartition> assigned = Arrays.asList(t1p, t2p);
final List<TopicPartition> owned = Collections.emptyList();
subscriptions.subscribe(Pattern.compile("test.*"), rebalanceListener);
// partially update the metadata with one topic first,
// let the leader to refresh metadata during assignment
client.updateMetadata(RequestTestUtils.metadataUpdateWith(1, singletonMap(topic1, 1)));
client.prepareResponse(groupCoordinatorResponse(node, Errors.NONE));
coordinator.ensureCoordinatorReady(time.timer(Long.MAX_VALUE));
// normal join group
Map<String, List<String>> memberSubscriptions = singletonMap(consumerId, singletonList(topic1));
partitionAssignor.prepare(singletonMap(consumerId, assigned));
client.prepareResponse(joinGroupLeaderResponse(1, consumerId, memberSubscriptions, Errors.NONE));
client.prepareResponse(body -> {
SyncGroupRequest sync = (SyncGroupRequest) body;
return sync.data().memberId().equals(consumerId) && sync.data().generationId() == 1 && sync.groupAssignments().containsKey(consumerId);
}, syncGroupResponse(assigned, Errors.NONE));
// expect client to force updating the metadata, if yes gives it both topics
client.prepareMetadataUpdate(metadataResponse);
coordinator.poll(time.timer(Long.MAX_VALUE));
assertFalse(coordinator.rejoinNeededOrPending());
assertEquals(2, subscriptions.numAssignedPartitions());
assertEquals(2, subscriptions.metadataTopics().size());
assertEquals(2, subscriptions.subscription().size());
// callback not triggered at all since there's nothing to be revoked
assertEquals(0, rebalanceListener.revokedCount);
assertNull(rebalanceListener.revoked);
assertEquals(1, rebalanceListener.assignedCount);
assertEquals(getAdded(owned, assigned), rebalanceListener.assigned);
}
Aggregations