Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/src/main/java/tech/ydb/core/Issue.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tech.ydb.core;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -146,7 +147,8 @@ public boolean equals(Object o) {
&& Objects.equals(position, issue.position)
&& Objects.equals(endPosition, issue.endPosition)
&& Objects.equals(message, issue.message)
&& severity == issue.severity;
&& severity == issue.severity
&& Arrays.equals(issues, issue.issues);
}

@Override
Expand All @@ -156,6 +158,7 @@ public int hashCode() {
result = 31 * result + code;
result = 31 * result + message.hashCode();
result = 31 * result + severity.hashCode();
result = 31 * result + Arrays.hashCode(issues);
return result;
}

Expand Down
28 changes: 27 additions & 1 deletion core/src/test/java/tech/ydb/core/IssueTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tech.ydb.core;

import tech.ydb.core.Issue.Position;
import org.junit.Assert;
import org.junit.Test;

import tech.ydb.core.Issue.Position;


/**
* @author Sergey Polovko
Expand Down Expand Up @@ -37,4 +38,29 @@ public void testToString() {
" 11:22: #4 message (S_WARNING)\n" +
" 11:22 at file.cpp: #5 message (S_WARNING)", x.toString());
}

@Test
public void testEquals() {
Issue nested1 = Issue.of(1, "nested 1", Issue.Severity.WARNING);
Issue nested2 = Issue.of(2, "nested 2", Issue.Severity.WARNING);

Issue plain = Issue.of(7, "cause", Issue.Severity.FATAL);
Issue samePlain = Issue.of(7, "cause", Issue.Severity.FATAL);

Assert.assertEquals(plain, samePlain);
Assert.assertEquals(plain.hashCode(), samePlain.hashCode());
Assert.assertNotEquals(plain, Issue.of(8, "root cause", Issue.Severity.FATAL));
Assert.assertNotEquals(plain, null);

Issue withNested = Issue.of(Position.EMPTY, Position.EMPTY, 7, "cause", Issue.Severity.FATAL, nested1);
Issue withSameNested = Issue.of(Position.EMPTY, Position.EMPTY, 7, "cause", Issue.Severity.FATAL, nested1);
Issue withOtherNested = Issue.of(Position.EMPTY, Position.EMPTY, 7, "cause", Issue.Severity.FATAL, nested2);

Assert.assertEquals(withNested, withSameNested);
Assert.assertEquals(withNested.hashCode(), withSameNested.hashCode());

// issues differing only in their nested issues are different issues
Assert.assertNotEquals(withNested, withOtherNested);
Assert.assertNotEquals(withNested, plain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,13 @@ public void testNoTxStatement() {

Assert.assertFalse(result.isSuccess());
Assert.assertEquals(StatusCode.PRECONDITION_FAILED, result.getStatus().getCode());
Issue issue = Issue.of(2012,
Issue issue = Issue.of(
Issue.Position.EMPTY,
Issue.Position.EMPTY,
2012,
"Constraint violated. Table: `" + ydbTransport.getDatabase() + "/" + TEST_TABLE + "`.",
Issue.Severity.ERROR
Issue.Severity.ERROR,
Issue.of(2012, "Conflict with existing key.", Issue.Severity.ERROR)
);
Assert.assertArrayEquals(new Issue[] { issue }, result.getStatus().getIssues());

Expand Down
Loading