void importPlaylistItems(
      List<MusicPlaylistItem> playlistItems,
      IdempotentImportExecutor executor,
      UUID jobId,
      TokensAndUrlAuthData authData)
      throws Exception {
    if (playlistItems != null && !playlistItems.isEmpty()) {
      Map<String, List<MusicPlaylistItem>> playlistItemsByPlaylist =
          playlistItems.stream()
              .filter(playlistItem -> !executor.isKeyCached(playlistItem.toString()))
              .collect(Collectors.groupingBy(MusicPlaylistItem::getPlaylistId));

      for (Entry<String, List<MusicPlaylistItem>> playlistEntry :
          playlistItemsByPlaylist.entrySet()) {
        String originalPlaylistId = playlistEntry.getKey();
        UnmodifiableIterator<List<MusicPlaylistItem>> batches =
            Iterators.partition(playlistEntry.getValue().iterator(), PLAYLIST_ITEM_BATCH_SIZE);
        while (batches.hasNext()) {
          importPlaylistItemBatch(jobId, authData, batches.next(), executor, originalPlaylistId);
        }
      }
    }

    return;
  }
@Test
  public void importPlaylistItemsCreatePlaylistFailure() throws Exception {
    MusicPlaylistItem playlistItem1 =
        new MusicPlaylistItem(
            new MusicRecording(
                "item1_isrc", null, 180000L, new MusicRelease("r1_icpn", null, null), null, false),
            "p1_id",
            1);
    MusicPlaylistItem playlistItem2 =
        new MusicPlaylistItem(
            new MusicRecording(
                "item2_isrc", null, 180000L, new MusicRelease("r1_icpn", null, null), null, false),
            "p1_id",
            1);

    // Run test
    googleMusicImporter.importPlaylistItems(
        Lists.newArrayList(playlistItem1, playlistItem2), executor, uuid, null);

    // Expected executor to have two errors
    assertThat(executor.getErrors()).hasSize(2);
    ErrorDetail errorDetail = executor.getErrors().iterator().next();
    assertEquals(String.valueOf(playlistItem1), errorDetail.id());
    assertThat(errorDetail.exception()).contains("Fail to create Playlist p1_id");
  }