use of org.apache.ignite.internal.table.TableImpl in project ignite-3 by apache.
the class ItTablesApiTest method testCreateDropTable.
/**
* Checks that if a table would be created/dropped in any cluster node, this action reflects on all others.
* Table management operations should pass in linearize order: if an action completed in one node,
* the result has to be visible to another one.
*
* @throws Exception If failed.
*/
@Test
public void testCreateDropTable() throws Exception {
clusterNodes.forEach(ign -> assertNull(ign.tables().table(TABLE_NAME)));
Ignite ignite1 = clusterNodes.get(1);
WatchListenerInhibitor ignite1Inhibitor = metastorageEventsInhibitor(ignite1);
ignite1Inhibitor.startInhibit();
Table table = createTable(clusterNodes.get(0), SCHEMA, SHORT_TABLE_NAME);
UUID tblId = ((TableImpl) table).tableId();
CompletableFuture<Table> tableByNameFut = CompletableFuture.supplyAsync(() -> {
return ignite1.tables().table(TABLE_NAME);
});
CompletableFuture<Table> tableByIdFut = CompletableFuture.supplyAsync(() -> {
try {
return ((IgniteTablesInternal) ignite1.tables()).table(tblId);
} catch (NodeStoppingException e) {
throw new AssertionError(e.getMessage());
}
});
// Therefore the table still doesn't exists locally, but API prevents getting null and waits events.
for (Ignite ignite : clusterNodes) {
if (ignite != ignite1) {
assertNotNull(ignite.tables().table(TABLE_NAME));
assertNotNull(((IgniteTablesInternal) ignite.tables()).table(tblId));
}
}
assertFalse(tableByNameFut.isDone());
assertFalse(tableByIdFut.isDone());
ignite1Inhibitor.stopInhibit();
assertNotNull(tableByNameFut.get(10, TimeUnit.SECONDS));
assertNotNull(tableByIdFut.get(10, TimeUnit.SECONDS));
ignite1Inhibitor.startInhibit();
clusterNodes.get(0).tables().dropTable(TABLE_NAME);
// Therefore the table still exists locally, but API prevents getting it.
for (Ignite ignite : clusterNodes) {
assertNull(ignite.tables().table(TABLE_NAME));
assertNull(((IgniteTablesInternal) ignite.tables()).table(tblId));
assertThrows(TableNotFoundException.class, () -> dropTable(ignite, SCHEMA, SHORT_TABLE_NAME));
dropTableIfExists(ignite, SCHEMA, SHORT_TABLE_NAME);
}
ignite1Inhibitor.stopInhibit();
}
use of org.apache.ignite.internal.table.TableImpl in project ignite-3 by apache.
the class ItTxDistributedTestSingleNode method before.
/**
* Initialize the test state.
*/
@Override
@BeforeEach
public void before() throws Exception {
int nodes = nodes();
int replicas = replicas();
assertTrue(nodes > 0);
assertTrue(replicas > 0);
List<NetworkAddress> localAddresses = findLocalAddresses(NODE_PORT_BASE, NODE_PORT_BASE + nodes);
var nodeFinder = new StaticNodeFinder(localAddresses);
nodeFinder.findNodes().parallelStream().map(addr -> startNode(testInfo, addr.toString(), addr.port(), nodeFinder)).forEach(cluster::add);
for (ClusterService node : cluster) {
assertTrue(waitForTopology(node, nodes, 1000));
}
log.info("The cluster has been started");
if (startClient()) {
client = startNode(testInfo, "client", NODE_PORT_BASE - 1, nodeFinder);
assertTrue(waitForTopology(client, nodes + 1, 1000));
log.info("The client has been started");
}
// Start raft servers. Each raft server can hold multiple groups.
raftServers = new HashMap<>(nodes);
txManagers = new HashMap<>(nodes);
executor = new ScheduledThreadPoolExecutor(20, new NamedThreadFactory(Loza.CLIENT_POOL_NAME));
for (int i = 0; i < nodes; i++) {
var raftSrv = new Loza(cluster.get(i), workDir);
raftSrv.start();
ClusterNode node = cluster.get(i).topologyService().localMember();
raftServers.put(node, raftSrv);
TableTxManagerImpl txMgr = new TableTxManagerImpl(cluster.get(i), new HeapLockManager());
txMgr.start();
txManagers.put(node, txMgr);
}
log.info("Raft servers have been started");
final String accountsName = "accounts";
final String customersName = "customers";
UUID accTblId = UUID.randomUUID();
UUID custTblId = UUID.randomUUID();
accRaftClients = startTable(accountsName, accTblId);
custRaftClients = startTable(customersName, custTblId);
log.info("Partition groups have been started");
TxManager txMgr;
if (startClient()) {
txMgr = new TxManagerImpl(client, new HeapLockManager());
} else {
// Collocated mode.
txMgr = txManagers.get(accRaftClients.get(0).clusterService().topologyService().localMember());
}
assertNotNull(txMgr);
igniteTransactions = new IgniteTransactionsImpl(txMgr);
this.accounts = new TableImpl(new InternalTableImpl(accountsName, accTblId, accRaftClients, 1, NetworkAddress::toString, txMgr, Mockito.mock(TableStorage.class)), new DummySchemaManagerImpl(ACCOUNTS_SCHEMA));
this.customers = new TableImpl(new InternalTableImpl(customersName, custTblId, custRaftClients, 1, NetworkAddress::toString, txMgr, Mockito.mock(TableStorage.class)), new DummySchemaManagerImpl(CUSTOMERS_SCHEMA));
log.info("Tables have been started");
}
use of org.apache.ignite.internal.table.TableImpl in project ignite-3 by apache.
the class StopCalciteModuleTest method before.
/**
* Before.
* TODO Documentation https://issues.apache.org/jira/browse/IGNITE-15859
*/
@BeforeEach
public void before(TestInfo testInfo) {
when(clusterSrvc.messagingService()).thenReturn(msgSrvc);
when(clusterSrvc.topologyService()).thenReturn(topologySrvc);
when(clusterSrvc.localConfiguration()).thenReturn(localCfg);
ClusterNode node = new ClusterNode("mock-node-id", NODE_NAME, null);
when(topologySrvc.localMember()).thenReturn(node);
when(topologySrvc.allMembers()).thenReturn(Collections.singleton(node));
SchemaDescriptor schemaDesc = new SchemaDescriptor(1, new Column[] { new Column(0, "ID", NativeTypes.INT32, false) }, new Column[] { new Column(1, "VAL", NativeTypes.INT32, false) });
schemaReg = new SchemaRegistryImpl(1, (v) -> schemaDesc, () -> INITIAL_SCHEMA_VERSION);
when(tbl.name()).thenReturn("PUBLIC.TEST");
// Mock create table (notify on register listener).
doAnswer(invocation -> {
EventListener<TableEventParameters> clo = (EventListener<TableEventParameters>) invocation.getArguments()[1];
clo.notify(new TableEventParameters(0, UUID.randomUUID(), "TEST", new TableImpl(tbl, schemaReg)), null);
return null;
}).when(tableManager).listen(eq(TableEvent.CREATE), any());
RowAssembler asm = new RowAssembler(schemaReg.schema(), 0, 0, 0, 0);
asm.appendInt(0);
asm.appendInt(0);
BinaryRow binaryRow = asm.build();
// Mock table scan
doAnswer(invocation -> {
int part = (int) invocation.getArguments()[0];
return (Flow.Publisher<BinaryRow>) s -> {
s.onSubscribe(new Flow.Subscription() {
@Override
public void request(long n) {
}
@Override
public void cancel() {
}
});
if (part == 0) {
for (int i = 0; i < ROWS; ++i) {
s.onNext(binaryRow);
}
}
s.onComplete();
};
}).when(tbl).scan(anyInt(), any());
LOG.info(">>>> Starting test {}", testInfo.getTestMethod().orElseThrow().getName());
}
use of org.apache.ignite.internal.table.TableImpl in project ignite-3 by apache.
the class SqlSchemaManagerImpl method awaitLatestTableSchema.
@Nullable
private IgniteTable awaitLatestTableSchema(UUID tableId) {
try {
TableImpl table = tableManager.table(tableId);
if (table == null) {
return null;
}
table.schemaView().waitLatestSchema();
return convert(table);
} catch (NodeStoppingException e) {
throw new IgniteInternalException(e);
}
}
Aggregations