File: testing.gradle

package info (click to toggle)
caffeine-cache 2.6.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 4,324 kB
  • sloc: java: 50,572; sh: 424; xml: 246; makefile: 2
file content (85 lines) | stat: -rw-r--r-- 2,873 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
 * The configuration to break cache tests into independant tasks.
 */
test {
  useTestNG()
  exclude 'com/github/benmanes/caffeine/cache/**'
}

def implementations = ['Caffeine', 'Guava']
def testNames = [
  'strongKeysAndStrongValues', 'strongKeysAndWeakValues', 'strongKeysAndSoftValues',
  'weakKeysAndStrongValues', 'weakKeysAndWeakValues', 'weakKeysAndSoftValues']
  .collectNested { [it, it + 'Stats'] }
  .collectNested { it.contains('StrongValues') ? [it + 'Sync', it + 'Async'] : (it + 'Sync') }
  .plus('slow')
  .collectNested { type -> implementations.collect { type + it + 'Test' } }.flatten()
  .findAll { !(it.contains('Guava') && it.contains('Async')) }

testNames.each { testName ->
  def isAsync = testName.contains('Async')
  def hasStats = testName.contains('Stats')
  def implementation = implementations.find { testName.contains(it) }
  def testType = testName - implementation - 'Test' - 'Stats' - 'Async' - 'Sync'
  def labels = testType.split('And').collect { it[0].toLowerCase() + it.substring(1) }

  task "${testName}"(type: Test) {
    it.useTestNG()
    group = 'Cache tests'
    description = 'Runs ' + labels.join(' with ') +
      implementation + ' and ' + (hasStats ? 'stats ' : 'no stats ') +
      (isAsync ? 'asynchronous' : 'synchronous') + ' tests.'
    include 'com/github/benmanes/caffeine/cache/**'

    if (labels.size() == 2) {
      def strength = labels.collect{ it.split('Keys|Values') }.flatten()
      systemProperties['keys'] = strength[0]
      systemProperties['values'] = strength[1]
      systemProperties['compute'] = isAsync ? 'async' : 'sync'
      systemProperties['stats'] = hasStats ? 'enabled' : 'disabled'
    }
    systemProperties['implementation'] = implementation

    // Configure task dependencies
    if (!name.startsWith('slow')) {
      tasks.test.dependsOn(it)
    }
  }
}

task isolatedTests(type: Test, group: 'Cache tests') {
  description = 'Tests that must be run in isolation'

  useTestNG()
  it.onlyIf { !System.env.'CI' }
}

task osgiTests(type: Test, group: 'Cache tests', description: 'Isolated OSGi tests') {
  enabled = !JavaVersion.current().isJava9Compatible()

  useJUnit()
  tasks.test.dependsOn(it)
  systemProperty 'caffeine.osgi.jar', project(':caffeine').jar.archivePath.path
}

tasks.withType(Test) {
  if (options instanceof TestNGOptions) {
    if (name.startsWith('slow')) {
      maxParallelForks = 2
      options.includeGroups = ['slow']
    } else if (name.startsWith('isolated')) {
      options.includeGroups = ['isolated']
    } else {
      options {
        excludeGroups = ['slow', 'isolated']
        parallel = 'methods'
        threadCount = 6
      }
    }
  }
}

task stress(type: JavaExec, group: 'Cache tests', description: 'Executes a stress test') {
  classpath sourceSets.test.runtimeClasspath
  main = 'com.github.benmanes.caffeine.cache.Stresser'
}