<commit_before>/*
 * Copyright 2013 Twitter Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.twitter.storehaus.cache

import org.specs2.mutable._

class TTLCacheTest extends Specification {
  val cache = Cache.ttl[String, Int](200)

  "TTLCache exhibits proper TTL-ness" in {
    val abCache = cache.putClocked("a" -> 1)._2.putClocked("b" -> 2)._2
    abCache.toNonExpiredMap must be_==(Map("a" -> 1, "b" -> 2))
    Thread.sleep(300)
    (abCache.putClocked("c" -> 3)._2).toNonExpiredMap must be_==(Map("c" -> 3))
  }

  "TTLCache does not return an expired value" in {
    val withV = cache.putClocked("a" -> 10)._2
    withV.getNonExpired("a") must be_==(Some(10))
    Thread.sleep(300)
    withV.getNonExpired("a") must be_==(None)
  }
}<commit_msg>Try be more lenient for travis low perf<commit_after>/*
 * Copyright 2013 Twitter Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.twitter.storehaus.cache

import org.specs2.mutable._
import com.twitter.util.Duration
import java.util.concurrent.TimeUnit


class TTLCacheTest extends Specification {
  val ttlMS = 600
  val cache = Cache.ttl[String, Int](Duration.fromTimeUnit(ttlMS, TimeUnit.MILLISECONDS))

  "TTLCache exhibits proper TTL-ness" in {
    val abCache = cache.putClocked("a" -> 1)._2.putClocked("b" -> 2)._2
    abCache.toNonExpiredMap must be_==(Map("a" -> 1, "b" -> 2))
    Thread.sleep(ttlMS)
    (abCache.putClocked("c" -> 3)._2).toNonExpiredMap must be_==(Map("c" -> 3))
  }

  "TTLCache does not return an expired value" in {
    val withV = cache.putClocked("a" -> 10)._2
    withV.getNonExpired("a") must be_==(Some(10))
    Thread.sleep(ttlMS)
    withV.getNonExpired("a") must be_==(None)
  }
}
{'fraction_non_alphanumeric': 0.12001463593121112, 'fraction_numerical': 0.021222100256128796, 'mean_word_length': 3.7465277777777777, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6002710', 'n_tokens_mistral': 915, 'n_tokens_neox': 869, 'n_words': 287}