Skip to content

Commit

Permalink
PGCK-367 updated tests (#66)
Browse files Browse the repository at this point in the history
updated tests
  • Loading branch information
baslo2 authored Jul 10, 2024
1 parent 5dd92a5 commit 3b8367a
Show file tree
Hide file tree
Showing 12 changed files with 299 additions and 91 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ pgSqlBlocks - это standalone приложение, написанное на
Выполните команду с использованием флага -DskipTests, к примеру: ```mvn package -P Linux-64 -DskipTests```

##### Для запуска тестов требуется:
1. Создать роль для тестового пользователя в БД:
```
CREATE ROLE pgsqlblocks_test LOGIN CREATEDB PASSWORD 'pgsqlblocks_test_user_password';
```

2. В случае необходимости, отредактировать файл application.conf в директории src/test/resources.

3. Выполните команду указав профиль, к примеру: ```mvn clean package -P Linux-64```.
1. Наличие [docker](https://docs.docker.com/engine/install/).
2. Выполните команду: ```mvn test```.

##### Запуск приложения

Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<config.version>1.4.3</config.version>
<commands.version>3.9.600</commands.version>
<equinox.version>3.10.600</equinox.version>
<testcontainers.version>1.19.8</testcontainers.version>
</properties>

<developers>
Expand Down Expand Up @@ -208,6 +209,11 @@
<version>${config.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand All @@ -223,6 +229,13 @@
<artifactId>org.eclipse.equinox.common</artifactId>
<version>${equinox.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
24 changes: 13 additions & 11 deletions src/main/java/ru/taximaxim/pgsqlblocks/common/models/DBBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*******************************************************************************/
package ru.taximaxim.pgsqlblocks.common.models;

import java.util.Objects;

public class DBBlock {

private final int blockingPid;
Expand Down Expand Up @@ -47,23 +49,23 @@ public boolean isGranted() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DBBlock)) return false;
if (this == o) {
return true;
}
if (!(o instanceof DBBlock)) {
return false;
}

DBBlock dbBlock = (DBBlock) o;

if (blockingPid != dbBlock.blockingPid) return false;
if (granted != dbBlock.granted) return false;
if (!relation.equals(dbBlock.relation)) return false;
return locktype.equals(dbBlock.locktype);
return blockingPid == dbBlock.blockingPid
&& relation.equals(dbBlock.relation)
&& locktype.equals(dbBlock.locktype)
&& granted == dbBlock.granted;
}

@Override
public int hashCode() {
int result = blockingPid;
result = 31 * result + relation.hashCode();
result = 31 * result + locktype.hashCode();
result = 31 * result + (granted ? 1 : 0);
return result;
return Objects.hash(blockingPid, relation, locktype, granted);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -69,15 +70,19 @@ public Date getCloseDate() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DBBlocksJournalProcess)) return false;
if (this == o) {
return true;
}
if (!(o instanceof DBBlocksJournalProcess)) {
return false;
}

DBBlocksJournalProcess other = (DBBlocksJournalProcess) o;

Date xactStart = process.getQuery().getXactStart();
Date otherXactStart = other.getProcess().getQuery().getXactStart();

boolean isSameXactStart = xactStart == null ? otherXactStart == null : xactStart.equals(otherXactStart);
boolean isSameXactStart = Objects.equals(xactStart, otherXactStart);
boolean isSamePid = process.getPid() == other.getProcess().getPid();

return isSameXactStart && isSamePid && childrenEquals(process.getChildren(), other.getProcess().getChildren());
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/ru/taximaxim/pgsqlblocks/common/models/DBModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public boolean equals(Object obj) {

DBModel other = (DBModel) obj;
return Objects.equals(databaseName, other.databaseName)
&& enabled == other.enabled && Objects.equals(host, other.host)
&& enabled == other.enabled
&& Objects.equals(host, other.host)
&& Objects.equals(name, other.name)
&& Objects.equals(password, other.password)
&& Objects.equals(port, other.port)
Expand All @@ -118,17 +119,6 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((databaseName == null) ? 0 : databaseName.hashCode());
result = prime * result + (enabled ? 1231 : 1237);
result = prime * result + ((host == null) ? 0 : host.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((port == null) ? 0 : port.hashCode());
result = prime * result + (readBackendType ? 1231 : 1237);
result = prime * result + ((user == null) ? 0 : user.hashCode());
return result;
return Objects.hash(databaseName, enabled, host, name, password, port, readBackendType, user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DBProcess)) return false;

DBProcess process = (DBProcess) o;

return pid == process.pid;
return pid == ((DBProcess) o).pid;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package ru.taximaxim.pgsqlblocks.common.models;

import java.util.Date;
import java.util.Objects;

/**
* Когда DBProcessQuery создается внутри десериализации resultSet, невозможно
Expand Down Expand Up @@ -89,25 +90,23 @@ public String toString() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DBProcessQuery)) return false;
if (this == o) {
return true;
}
if (!(o instanceof DBProcessQuery)) {
return false;
}

DBProcessQuery that = (DBProcessQuery) o;

if (slowQuery != that.slowQuery) return false;
if (!queryString.equals(that.queryString)) return false;
if (backendStart != null ? !backendStart.equals(that.backendStart) : that.backendStart != null) return false;
if (queryStart != null ? !queryStart.equals(that.queryStart) : that.queryStart != null) return false;
return xactStart != null ? xactStart.equals(that.xactStart) : that.xactStart == null;
return Objects.equals(queryString, that.queryString)
&& slowQuery == that.slowQuery
&& Objects.equals(backendStart, that.backendStart)
&& Objects.equals(queryStart, that.queryStart)
&& Objects.equals(xactStart, that.xactStart);
}

@Override
public int hashCode() {
int result = queryString.hashCode();
result = 31 * result + (slowQuery ? 1 : 0);
result = 31 * result + (backendStart != null ? backendStart.hashCode() : 0);
result = 31 * result + (queryStart != null ? queryStart.hashCode() : 0);
result = 31 * result + (xactStart != null ? xactStart.hashCode() : 0);
return result;
return Objects.hash(queryString, slowQuery, backendStart, queryStart, xactStart);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*******************************************************************************/
package ru.taximaxim.pgsqlblocks.common.models;

import java.util.Objects;

public class DBProcessQueryCaller {

private final String applicationName;
Expand Down Expand Up @@ -57,23 +59,22 @@ public String toString() {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DBProcessQueryCaller)) return false;
if (this == o) {
return true;
}
if (!(o instanceof DBProcessQueryCaller)) {
return false;
}

DBProcessQueryCaller that = (DBProcessQueryCaller) o;

if (!applicationName.equals(that.applicationName)) return false;
if (!databaseName.equals(that.databaseName)) return false;
if (!userName.equals(that.userName)) return false;
return client.equals(that.client);
return Objects.equals(applicationName, that.applicationName)
&& Objects.equals(databaseName, that.databaseName)
&& Objects.equals(userName, that.userName)
&& Objects.equals(client, that.client);
}

@Override
public int hashCode() {
int result = applicationName.hashCode();
result = 31 * result + databaseName.hashCode();
result = 31 * result + userName.hashCode();
result = 31 * result + client.hashCode();
return result;
return Objects.hash(applicationName, databaseName, userName, client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ private String getProcessesQuery() {
}
}

Connection getConnection() {
return connection;
}

public void addListener(DBControllerListener listener) {
listeners.add(listener);
}
Expand Down
Loading

0 comments on commit 3b8367a

Please sign in to comment.