Package com.github.hakko.musiccabinet.domain.model.aggr

Examples of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble


  @Test
  public void validateParameters() throws ApplicationException {

    final Track track = browserDao.getTracks(browserDao.getRandomTrackIds(1)).get(0);
    final LastFmUser user = new LastFmUser("lastFmUser", "sessionKey");
    final Scrobble scrobble = new Scrobble(user, track, false);

    final String method = UpdateNowPlayingClient.METHOD;

    new UpdateNowPlayingClient() {
      @Override
View Full Code Here


   
    // a second scrobble of the same track is just silently thrown away.
    // verify by checking that it's the original scrobble (check startTime)
    // that remains in the queue when a dupe is scrobbled.
   
    Scrobble scrobble1 = new Scrobble(user1, track1, false);
    Thread.sleep(3);
    Scrobble scrobble2 = new Scrobble(user1, track1, false);

    Message message1 = new GenericMessage<Scrobble>(scrobble1);
    Message message2 = new GenericMessage<Scrobble>(scrobble2);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message1, message2, null);
View Full Code Here

  public void previousScrobbleGetsRemovedOnImmediateOtherScrobble() throws InterruptedException, ApplicationException {

    // differently from test case above, a close subsequent scan of a
    // new track removes the previous scrobble from the queue (not the new).
   
    Scrobble scrobble1 = new Scrobble(user1, track1, false);
    Thread.sleep(3);
    Scrobble scrobble2 = new Scrobble(user1, track2, false);

    assertFalse(scrobble1.getStartTime().equals(scrobble2.getStartTime()));
   
    Message message1 = new GenericMessage<Scrobble>(scrobble1);
    Message message2 = new GenericMessage<Scrobble>(scrobble2);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message1, message2, null);
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void differentUsersCanScrobbleSameTrack() throws ApplicationException {
   
    Scrobble scrobble1 = new Scrobble(user1, track1, false);
    Scrobble scrobble2 = new Scrobble(user2, track1, false);

    Message message1 = new GenericMessage<Scrobble>(scrobble1);
    Message message2 = new GenericMessage<Scrobble>(scrobble2);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message1, message2, null);
   
    scrobbleService.setScrobbleChannel(scrobbleChannel);
    scrobbleService.receive();
   
    assertNotNull(scrobbleService.userScrobbles);
    assertEquals(2, scrobbleService.userScrobbles.keySet().size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble1.getLastFmUser()).size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble2.getLastFmUser()).size());
  }
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  @Test
  public void scrobblerIgnoresTooNewSubmissions() throws ApplicationException {

    Scrobble scrobble = new Scrobble(user1, track1, false);

    Message message = new GenericMessage<Scrobble>(scrobble);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message, (Message) null);

    scrobbleService.setScrobbleChannel(scrobbleChannel);
    scrobbleService.receive();

    scrobbleService.scrobbleTracks();
    assertNotNull(scrobbleService.userScrobbles);
    assertEquals(1, scrobbleService.userScrobbles.keySet().size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble.getLastFmUser()).size());
   
    scrobble.setStartTime(scrobble.getStartTime().minusSeconds(10));
    scrobbleService.scrobbleTracks();
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble.getLastFmUser()).size());

    scrobble.setStartTime(scrobble.getStartTime().minusMinutes(10));
    scrobbleService.scrobbleTracks();
    assertEquals(0, scrobbleService.userScrobbles.get(scrobble.getLastFmUser()).size());
  }
View Full Code Here

      if (message == null || message.equals(FINISHED_MESSAGE)) {
        break;
      } else {
        try {
          LOG.debug("Try updating now playing.");
          Scrobble scrobble = message.getPayload();
          Scrobble previous = getPrevious(scrobble);
          LOG.debug("previous: " + previous + ", scrobble = " + scrobble);
          if (previous != null && tooClose(scrobble, previous) &&
            scrobble.getTrack().getId() == previous.getTrack().getId()) {
            LOG.debug("Same track was scrobbled just recently, ignore.");
          } else {
            addScrobble(scrobble);
            WSResponse wsResponse = client.updateNowPlaying(message.getPayload());
            LOG.debug("Successful: " + wsResponse.wasCallSuccessful());
View Full Code Here

    }
  }
 
  private void addScrobble(Scrobble scrobble) {
    ConcurrentLinkedDeque<Scrobble> deque = userScrobbles.get(scrobble.getLastFmUser());
    Scrobble tail;
    while ((tail = deque.peekLast()) != null && tooClose(tail, scrobble)) {
      // indicates the occurrence of a previous track that was played for a few
      // seconds, and that should be removed
      deque.pollLast();
    }
View Full Code Here

    allowedDiff = min(allowedDiff, MIN_TIME);
    return secondsBetween(prev.getStartTime(), next).getSeconds() < allowedDiff;
  }

  private void scrobbleTracks() {
    Scrobble head;
    for (LastFmUser lastFmUser : userScrobbles.keySet()) {
      ConcurrentLinkedDeque<Scrobble> deque = userScrobbles.get(lastFmUser);
      while ((head = deque.peekFirst()) != null) {
        if (!tooClose(head, new DateTime())) {
          // update play stats
View Full Code Here

   *
   * Submission: Whether this is a "scrobble" or a "now playing" notification.
   */
  public void scrobble(String lastFmUsername, Track track, boolean submission) {
    LastFmUser lastFmUser = lastFmDao.getLastFmUser(lastFmUsername);
    Scrobble scrobble = new Scrobble(lastFmUser, track, submission);
   
    scrobbleChannel.send(new GenericMessage<Scrobble>(scrobble));
   
    if (!started.getAndSet(true)) {
      startScrobblingService();
View Full Code Here

  @SuppressWarnings("unchecked")
  protected void receive() throws ApplicationException {
    Message<Scrobble> message;
    while ((message = (Message<Scrobble>) scrobbleChannel.receive()) != null) {
      Scrobble scrobble = message.getPayload();
      Scrobble previous = getPrevious(scrobble);
      if (previous != null && tooClose(scrobble, previous) &&
          scrobble.getTrack().getId() == previous.getTrack().getId()) {
        LOG.debug("Same track was scrobbled just recently, ignore.");
      } else {
        addScrobble(scrobble);
        WSResponse wsResponse = nowPlayingClient.updateNowPlaying(scrobble);
        if (!wsResponse.wasCallSuccessful()) {
View Full Code Here

TOP

Related Classes of com.github.hakko.musiccabinet.domain.model.aggr.Scrobble

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.