Skip to content

Commit

Permalink
Run TestMemoryMetadata in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Aug 30, 2023
1 parent e8a5131 commit e38dfd7
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.security.TrinoPrincipal;
import io.trino.testing.TestingNodeManager;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.util.List;
Expand All @@ -50,21 +49,13 @@
import static org.testng.Assert.expectThrows;
import static org.testng.Assert.fail;

@Test(singleThreaded = true)
public class TestMemoryMetadata
{
private MemoryMetadata metadata;

@BeforeMethod
public void setUp()
{
metadata = new MemoryMetadata(new TestingNodeManager());
}

@Test
public void tableIsCreatedAfterCommits()
{
assertNoTables();
MemoryMetadata metadata = createMetadata();
assertNoTables(metadata);

SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");

Expand All @@ -84,7 +75,8 @@ public void tableIsCreatedAfterCommits()
@Test
public void tableAlreadyExists()
{
assertNoTables();
MemoryMetadata metadata = createMetadata();
assertNoTables(metadata);

SchemaTableName test1Table = new SchemaTableName("default", "test1");
SchemaTableName test2Table = new SchemaTableName("default", "test2");
Expand All @@ -105,7 +97,8 @@ public void tableAlreadyExists()
@Test
public void testActiveTableIds()
{
assertNoTables();
MemoryMetadata metadata = createMetadata();
assertNoTables(metadata);

SchemaTableName firstTableName = new SchemaTableName("default", "first_table");
metadata.createTable(SESSION, new ConnectorTableMetadata(firstTableName, ImmutableList.of(), ImmutableMap.of()), false);
Expand All @@ -129,7 +122,8 @@ public void testActiveTableIds()
@Test
public void testReadTableBeforeCreationCompleted()
{
assertNoTables();
MemoryMetadata metadata = createMetadata();
assertNoTables(metadata);

SchemaTableName tableName = new SchemaTableName("default", "temp_table");

Expand All @@ -148,6 +142,7 @@ public void testReadTableBeforeCreationCompleted()
@Test
public void testCreateSchema()
{
MemoryMetadata metadata = createMetadata();
assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));
metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default", "test"));
Expand All @@ -171,6 +166,7 @@ public void testCreateSchema()
public void testCreateViewWithoutReplace()
{
SchemaTableName test = new SchemaTableName("test", "test_view");
MemoryMetadata metadata = createMetadata();
metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
try {
metadata.createView(SESSION, test, testingViewDefinition("test"), false);
Expand All @@ -188,6 +184,7 @@ public void testCreateViewWithReplace()
{
SchemaTableName test = new SchemaTableName("test", "test_view");

MemoryMetadata metadata = createMetadata();
metadata.createSchema(SESSION, "test", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
metadata.createView(SESSION, test, testingViewDefinition("aaa"), true);
metadata.createView(SESSION, test, testingViewDefinition("bbb"), true);
Expand All @@ -203,6 +200,7 @@ public void testCreatedViewShouldBeListedAsTable()
String schemaName = "test";
SchemaTableName viewName = new SchemaTableName(schemaName, "test_view");

MemoryMetadata metadata = createMetadata();
metadata.createSchema(SESSION, schemaName, ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
metadata.createView(SESSION, viewName, testingViewDefinition("aaa"), true);

Expand All @@ -213,6 +211,7 @@ public void testCreatedViewShouldBeListedAsTable()
@Test
public void testViews()
{
MemoryMetadata metadata = createMetadata();
SchemaTableName test1 = new SchemaTableName("test", "test_view1");
SchemaTableName test2 = new SchemaTableName("test", "test_view2");
SchemaTableName test3 = new SchemaTableName("test", "test_view3");
Expand Down Expand Up @@ -277,6 +276,7 @@ public void testViews()
@Test
public void testCreateTableAndViewInNotExistSchema()
{
MemoryMetadata metadata = createMetadata();
assertEquals(metadata.listSchemaNames(SESSION), ImmutableList.of("default"));

SchemaTableName table1 = new SchemaTableName("test1", "test_schema_table1");
Expand Down Expand Up @@ -308,6 +308,7 @@ public void testCreateTableAndViewInNotExistSchema()
public void testRenameTable()
{
SchemaTableName tableName = new SchemaTableName("test_schema", "test_table_to_be_renamed");
MemoryMetadata metadata = createMetadata();
metadata.createSchema(SESSION, "test_schema", ImmutableMap.of(), new TrinoPrincipal(USER, SESSION.getUser()));
ConnectorOutputTableHandle table = metadata.beginCreateTable(
SESSION,
Expand Down Expand Up @@ -335,7 +336,7 @@ public void testRenameTable()
assertEquals(metadata.listTables(SESSION, Optional.of("test_different_schema")), ImmutableList.of(differentSchemaTableName));
}

private void assertNoTables()
private static void assertNoTables(MemoryMetadata metadata)
{
assertEquals(metadata.listTables(SESSION, Optional.empty()), ImmutableList.of(), "No table was expected");
}
Expand All @@ -351,4 +352,9 @@ private static ConnectorViewDefinition testingViewDefinition(String sql)
Optional.empty(),
true);
}

private static MemoryMetadata createMetadata()
{
return new MemoryMetadata(new TestingNodeManager());
}
}

0 comments on commit e38dfd7

Please sign in to comment.