github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cmd/roachtest/pgjdbc.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package main
    12  
    13  import (
    14  	"context"
    15  	"fmt"
    16  	"regexp"
    17  )
    18  
    19  var pgjdbcReleaseTagRegex = regexp.MustCompile(`^REL(?P<major>\d+)\.(?P<minor>\d+)\.(?P<point>\d+)$`)
    20  
    21  // This test runs pgjdbc's full test suite against a single cockroach node.
    22  
    23  func registerPgjdbc(r *testRegistry) {
    24  	runPgjdbc := func(
    25  		ctx context.Context,
    26  		t *test,
    27  		c *cluster,
    28  	) {
    29  		if c.isLocal() {
    30  			t.Fatal("cannot be run in local mode")
    31  		}
    32  		node := c.Node(1)
    33  		t.Status("setting up cockroach")
    34  		c.Put(ctx, cockroach, "./cockroach", c.All())
    35  		c.Start(ctx, t, c.All())
    36  
    37  		version, err := fetchCockroachVersion(ctx, c, node[0])
    38  		if err != nil {
    39  			t.Fatal(err)
    40  		}
    41  
    42  		if err := alterZoneConfigAndClusterSettings(ctx, version, c, node[0]); err != nil {
    43  			t.Fatal(err)
    44  		}
    45  
    46  		t.Status("cloning pgjdbc and installing prerequisites")
    47  		// Report the latest tag, but do not use it. The newest versions produces output that breaks our xml parser,
    48  		// and we want to pin to the working version for now.
    49  		latestTag, err := repeatGetLatestTag(
    50  			ctx, c, "pgjdbc", "pgjdbc", pgjdbcReleaseTagRegex,
    51  		)
    52  		if err != nil {
    53  			t.Fatal(err)
    54  		}
    55  		c.l.Printf("Latest pgjdbc release is %s.", latestTag)
    56  
    57  		if err := repeatRunE(
    58  			ctx, c, node, "update apt-get", `sudo apt-get -qq update`,
    59  		); err != nil {
    60  			t.Fatal(err)
    61  		}
    62  
    63  		if err := repeatRunE(
    64  			ctx,
    65  			c,
    66  			node,
    67  			"install dependencies",
    68  			`sudo apt-get -qq install default-jre openjdk-8-jdk-headless maven`,
    69  		); err != nil {
    70  			t.Fatal(err)
    71  		}
    72  
    73  		if err := repeatRunE(
    74  			ctx, c, node, "remove old pgjdbc", `rm -rf /mnt/data1/pgjdbc`,
    75  		); err != nil {
    76  			t.Fatal(err)
    77  		}
    78  
    79  		if err := repeatGitCloneE(
    80  			ctx,
    81  			t.l,
    82  			c,
    83  			"https://github.com/pgjdbc/pgjdbc.git",
    84  			"/mnt/data1/pgjdbc",
    85  			"REL42.2.9",
    86  			node,
    87  		); err != nil {
    88  			t.Fatal(err)
    89  		}
    90  
    91  		// In order to get pgjdbc's test suite to connect to cockroach, we have
    92  		// to override settings in build.local.properties
    93  		if err := repeatRunE(
    94  			ctx,
    95  			c,
    96  			node,
    97  			"configuring tests for cockroach only",
    98  			fmt.Sprintf(
    99  				"echo \"%s\" > /mnt/data1/pgjdbc/build.local.properties", pgjdbcDatabaseParams,
   100  			),
   101  		); err != nil {
   102  			t.Fatal(err)
   103  		}
   104  
   105  		t.Status("building pgjdbc (without tests)")
   106  		// Build pgjdbc and run a single test, this step involves some
   107  		// downloading, so it needs a retry loop as well. Just building was not
   108  		// enough as the test libraries are not downloaded unless at least a
   109  		// single test is invoked.
   110  		if err := repeatRunE(
   111  			ctx,
   112  			c,
   113  			node,
   114  			"building pgjdbc (without tests)",
   115  			`cd /mnt/data1/pgjdbc/pgjdbc/ && mvn -Dtest=OidToStringTest test`,
   116  		); err != nil {
   117  			t.Fatal(err)
   118  		}
   119  
   120  		blacklistName, expectedFailures, ignorelistName, ignorelist := pgjdbcBlacklists.getLists(version)
   121  		if expectedFailures == nil {
   122  			t.Fatalf("No pgjdbc blacklist defined for cockroach version %s", version)
   123  		}
   124  		status := fmt.Sprintf("Running cockroach version %s, using blacklist %s", version, blacklistName)
   125  		if ignorelist != nil {
   126  			status = fmt.Sprintf("Running cockroach version %s, using blacklist %s, using ignorelist %s",
   127  				version, blacklistName, ignorelistName)
   128  		}
   129  		c.l.Printf("%s", status)
   130  
   131  		t.Status("running pgjdbc test suite")
   132  		// Note that this is expected to return an error, since the test suite
   133  		// will fail. And it is safe to swallow it here.
   134  		_ = c.RunE(ctx, node,
   135  			`cd /mnt/data1/pgjdbc/pgjdbc/ && mvn test`,
   136  		)
   137  
   138  		_ = c.RunE(ctx, node,
   139  			`mkdir -p ~/logs/report/pgjdbc-results`,
   140  		)
   141  
   142  		t.Status("collecting the test results")
   143  		// Copy all of the test results to the cockroach logs directory to be
   144  		// copied to the artifacts.
   145  
   146  		// Copy the individual test result files.
   147  		if err := repeatRunE(
   148  			ctx,
   149  			c,
   150  			node,
   151  			"copy test result files",
   152  			`cp /mnt/data1/pgjdbc/pgjdbc/target/surefire-reports ~/logs/report/pgjdbc-results -a`,
   153  		); err != nil {
   154  			t.Fatal(err)
   155  		}
   156  
   157  		// Load the list of all test results files and parse them individually.
   158  		// Files are here: /mnt/data1/pgjdbc/pgjdbc-core/target/test-results/test
   159  		output, err := repeatRunWithBuffer(
   160  			ctx,
   161  			c,
   162  			t.l,
   163  			node,
   164  			"get list of test files",
   165  			`ls /mnt/data1/pgjdbc/pgjdbc/target/surefire-reports/*.xml`,
   166  		)
   167  		if err != nil {
   168  			t.Fatal(err)
   169  		}
   170  		if len(output) == 0 {
   171  			t.Fatal("could not find any test result files")
   172  		}
   173  
   174  		parseAndSummarizeJavaORMTestsResults(
   175  			ctx, t, c, node, "pgjdbc" /* ormName */, output,
   176  			blacklistName, expectedFailures, ignorelist, version, latestTag,
   177  		)
   178  	}
   179  
   180  	r.Add(testSpec{
   181  		MinVersion: "v2.1.0",
   182  		Name:       "pgjdbc",
   183  		Owner:      OwnerAppDev,
   184  		Cluster:    makeClusterSpec(1),
   185  		Tags:       []string{`default`, `driver`},
   186  		Run: func(ctx context.Context, t *test, c *cluster) {
   187  			runPgjdbc(ctx, t, c)
   188  		},
   189  	})
   190  }
   191  
   192  const pgjdbcDatabaseParams = `
   193  server=localhost
   194  port=26257
   195  secondaryServer=localhost
   196  secondaryPort=5433
   197  secondaryServer2=localhost
   198  secondaryServerPort2=5434
   199  database=defaultdb
   200  username=root
   201  password=
   202  privilegedUser=root
   203  privilegedPassword=
   204  sspiusername=testsspi
   205  preparethreshold=5
   206  loggerLevel=DEBUG
   207  loggerFile=target/pgjdbc-tests.log
   208  protocolVersion=0
   209  sslpassword=sslpwd
   210  `