CacheQueryHandlerImpl implements CacheQueryHandler { @NotNull @Override public Collection<P4LocalChangelist> getCachedOpenedChangelists(@NotNull ClientConfig config) { final Map<P4ChangelistId, P4LocalChangelistImpl.Builder> changelists = new HashMap<>(); try { cache.getChangelistCacheStore().getPendingChangelists().forEach( (cl) -> changelists.put(cl.getChangelistId(), new P4LocalChangelistImpl.Builder().withSrc(cl))); if (LOG.isDebugEnabled()) { LOG.debug("cached pending changelists: " + changelists.keySet()); } cache.read(config, (store) -> store.getChangelists().forEach( (cl) -> changelists .put(cl.getChangelistId(), new P4LocalChangelistImpl.Builder().withSrc(cl)))); if (LOG.isDebugEnabled()) { LOG.debug("cached pending + cached queried changelists: " + changelists.keySet()); } pendingClientActions(config, (action) -> { switch (action.getCmd()) { case DELETE_CHANGELIST: { DeleteChangelistAction a = toDeleteChangelistAction(action); changelists.remove(a.getChangelistId()); break; } case MOVE_FILES_TO_CHANGELIST: { MoveFilesToChangelistAction a = toMoveFilesToChangelistAction(action); for (P4LocalChangelistImpl.Builder builder: changelists.values()) { if (builder.is(a.getChangelistId())) { builder.addFiles(a.getFiles()); } else { builder.removeFiles(a.getFiles()); } } break; } case EDIT_CHANGELIST_DESCRIPTION: { EditChangelistAction a = toEditChangelistAction(action); P4LocalChangelistImpl.Builder builder = changelists.get(a.getChangelistId()); if (builder != null) { builder.withComment(a.getComment()); } break; } case ADD_JOB_TO_CHANGELIST: { AddJobToChangelistAction a = toAddJobToChangelistAction(action); P4LocalChangelistImpl.Builder builder = changelists.get(a.getChangelistId()); if (builder != null) { builder.withJob(a.getJob()); } break; } case REMOVE_JOB_FROM_CHANGELIST: { RemoveJobFromChangelistAction a = toRemoveJobFromChangelistAction(action); P4LocalChangelistImpl.Builder builder = changelists.get(a.getChangelistId()); if (builder != null) { builder.withJobRemoved(a.getJob()); } } } }); } catch (InterruptedException e) { reportCacheWaitError(e); } if (LOG.isDebugEnabled()) { LOG.debug("final evaluated cached changelists: " + changelists.keySet()); } return changelists.values().stream().map(P4LocalChangelistImpl.Builder::build).collect(Collectors.toList()); } CacheQueryHandlerImpl(@Nullable Project project, @NotNull ProjectCacheStore cache); @NotNull @Override Collection<P4LocalChangelist> getCachedOpenedChangelists(@NotNull ClientConfig config); @NotNull @Override Collection<P4LocalFile> getCachedOpenedFiles(@NotNull ClientConfig config); @Nullable @Override P4RemoteChangelist getCachedChangelist(P4ServerName serverName, P4ChangelistId changelistId); @Nullable @Override P4JobSpec getCachedJobSpec(P4ServerName serverName); @NotNull @Override Collection<P4WorkspaceSummary> getCachedClientsForUser(@NotNull P4ServerName serverName,
            @NotNull String username); @Override int getEstimateSize();  }
@Test void getCachedOpenedChangelists_noCacheForClient() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertEmpty(changes); }
@Test void getCachedOpenedChangelists_noActions() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertSize(1, changes); assertEqualChangelists(cl1, changes.iterator().next()); }
@Test void getCachedOpenedChangelists_deleteAction() { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); projectStore.addPendingAction(ActionStore.createPendingAction( clientConfig.getClientServerRef(), new DeleteChangelistAction(cl1.getChangelistId()))); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); Collection<P4LocalChangelist> changes = query.getCachedOpenedChangelists(clientConfig); assertSize(0, changes); }
@Test void getCachedOpenedChangelists_createAction() throws InterruptedException { MockConfigPart configPart = createConfigPart(); ServerConfig serverConfig = ServerConfig.createFrom(configPart); ClientConfig clientConfig = ClientConfig.createFrom(serverConfig, configPart); ProjectCacheStore projectStore = new ProjectCacheStore(); CacheQueryHandlerImpl query = new CacheQueryHandlerImpl(idea.getMockProject(), projectStore); ClientQueryCacheStore clientStore = new ClientQueryCacheStore(clientConfig.getClientServerRef()); P4LocalChangelist cl1 = new P4LocalChangelistImpl.Builder() .withChangelistId(new P4ChangelistIdImpl(1, clientConfig.getClientServerRef())) .withComment("comment 1") .withClientname(clientConfig.getClientname()) .withUsername(serverConfig.getUsername()) .build(); CreateChangelistAction addChangelistAction = new CreateChangelistAction( clientConfig.getClientServerRef(), "my comment", "local-id"); MockLocalChangeList ideChangeList = new MockLocalChangeList(); ideChangeList.setName("id:123"); IdeChangelistMap ideChangelistMap = new IdeChangelistMapImpl(idea.getMockProject(), projectStore.getChangelistCacheStore()); ideChangelistMap.setMapping(addChangelistAction, ideChangeList); projectStore.addPendingAction(ActionStore.createPendingAction( clientConfig.getClientServerRef(), addChangelistAction)); clientStore.setChangelists(cl1); projectStore.addCache(clientStore); List<P4LocalChangelist> changes = new ArrayList<>(query.getCachedOpenedChangelists(clientConfig)); assertSize(2, changes); P4LocalChangelist res1 = changes.get(0).getChangelistId().getChangelistId() == 1 ? changes.get(0) : changes.get(1); P4LocalChangelist res2 = changes.get(0).getChangelistId().getChangelistId() == 1 ? changes.get(1) : changes.get(0); assertEqualChangelists(cl1, res1); assertEquals( projectStore.getChangelistCacheStore() .getPendingChangelist(addChangelistAction, false).getChangelistId().getChangelistId(), res2.getChangelistId().getChangelistId()); assertEquals("my comment", res2.getComment()); assertEquals(clientConfig.getClientname(), res2.getClientname()); assertEquals("(unknown)", res2.getUsername()); assertEmpty(res2.getAttachedJobs()); assertEmpty(res2.getShelvedFiles()); assertEmpty(res2.getFiles()); }