All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.snowflake.client.core.BaseIncidentTest Maven / Gradle / Ivy

package net.snowflake.client.core;

import net.snowflake.client.AbstractDriverIT;
import net.snowflake.client.jdbc.SnowflakeConnectionV1;
import net.snowflake.client.jdbc.SnowflakeDriver;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;

import java.sql.*;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * Created by hyu on 6/7/16.
 */
public class BaseIncidentTest extends AbstractDriverIT {
  protected static int maxLogDumps = 5;
  protected static long maxDumpSizeMb = 1;

  private static Logger logger = Logger.getLogger(BaseIncidentTest.class.getName());

  @BeforeClass
  public static void setUpClass() throws SQLException, ClassNotFoundException
  {
    Class.forName("net.snowflake.client.jdbc.SnowflakeDriver");
    Properties properties = new Properties();
    properties.put("user", "admin");
    properties.put("password", "test");
    properties.put("account", "snowflake");
    Connection connection = getConnection(true, false, 0, properties);
    Statement statement = connection.createStatement();
    statement.execute("alter system set CLIENT_DISABLE_INCIDENTS=false");
    statement.execute("alter system set ENABLE_CLIENT_SIDE_INCIDENTS=true");
    statement.execute("alter system set CLIENT_INCIDENT_ACCT_THROTTLE_LIM=1000");
    statement.close();
    connection.close();
  }

  @AfterClass
  public static void tearDownClass() throws SQLException
  {
    Properties properties = new Properties();
    properties.put("user", "admin");
    properties.put("password", "test");
    properties.put("account", "snowflake");
    Connection connection = getConnection(true, false, 0, properties);
    Statement statement = connection.createStatement();
    statement.execute("alter system set CLIENT_DISABLE_INCIDENTS=default");
    statement.execute("alter system set ENABLE_CLIENT_SIDE_INCIDENTS=default");
    statement.execute("alter system set CLIENT_INCIDENT_ACCT_THROTTLE_LIM=default");
    statement.close();
    connection.close();
  }

  @Before
  public void setUp()
  {
    System.setProperty(EventHandler.MAX_SIZE_DUMPS_MB_PROP,
        String.valueOf(maxDumpSizeMb));
    System.setProperty(EventHandler.MAX_NUM_DUMP_FILES_PROP,
        String.valueOf(maxLogDumps));
    System.setProperty(EventHandler.DISABLE_DUMP_COMPR_PROP, "true");
  }

  @After
  public void tearDown()
  {
  }

  protected void generateIncidentWithSignature(String signature, boolean silenceIncidents) throws SQLException
  {
  Properties properties = new Properties();
  properties.put("user", "admin");
  properties.put("password", "test");
  properties.put("account", "snowflake");
  Connection connection = getConnection(false, false, 0, properties);
  if (silenceIncidents) {
    connection.createStatement().execute("alter session set SILENCE_INCIDENTS=true");
  }
  SFSession session = ((SnowflakeConnectionV1)connection).getSfSession();
  IncidentUtil.generateIncident(session, signature, null, null, null, null);
  connection.close();
  }

  // If the expectedNumberOfIncidents is -1, it indicates we don't
  // care about exact number of records
  protected void verifyIncidentRegisteredInGS(String sourceErrorSignature, int expectedNumberOfIncidents)
      throws SQLException
  {
    Connection connection = getConnection(false, false, 0, null);
    Statement statement = connection.createStatement();
    statement.execute("select $1:\"WAIncidentDPO:primary\" " +
        "from table(dposcan('" +
        "{\"slices\" : [{\"name\" : \"WAIncidentDPO:primary\"}]}')) dpo " +
        "where $1:\"WAIncidentDPO:primary\":\"sourceErrorSignature\" like '%"
        + sourceErrorSignature + "%'");
    ResultSet resultSet = statement.getResultSet();
    int actualCount = 0;
    while(resultSet.next())
    {
        actualCount++;
    }

    if (expectedNumberOfIncidents == -1)
      assertTrue(actualCount > 0);
    else
      assertEquals(expectedNumberOfIncidents, actualCount);

    connection.close();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy