View Javadoc
1   /*
2    *  Copyright 2022 Red Hat
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.jboss.hal.testsuite.test.configuration.jca;
17  
18  import org.jboss.arquillian.core.api.annotation.Inject;
19  import org.jboss.arquillian.graphene.page.Page;
20  import org.jboss.hal.resources.Ids;
21  import org.jboss.hal.resources.Names;
22  import org.jboss.hal.testsuite.Console;
23  import org.jboss.hal.testsuite.CrudOperations;
24  import org.jboss.hal.testsuite.container.WildFlyContainer;
25  import org.jboss.hal.testsuite.fragment.FormFragment;
26  import org.jboss.hal.testsuite.fragment.TableFragment;
27  import org.jboss.hal.testsuite.fragment.TabsFragment;
28  import org.jboss.hal.testsuite.page.configuration.JcaPage;
29  import org.jboss.hal.testsuite.test.Manatoko;
30  import org.junit.jupiter.api.BeforeAll;
31  import org.junit.jupiter.api.BeforeEach;
32  import org.junit.jupiter.api.Test;
33  import org.testcontainers.junit.jupiter.Container;
34  import org.testcontainers.junit.jupiter.Testcontainers;
35  import org.wildfly.extras.creaper.core.online.OnlineManagementClient;
36  import org.wildfly.extras.creaper.core.online.operations.Operations;
37  import org.wildfly.extras.creaper.core.online.operations.Values;
38  
39  import static java.util.Arrays.asList;
40  import static org.jboss.arquillian.graphene.Graphene.waitGui;
41  import static org.jboss.hal.dmr.ModelDescriptionConstants.MAX_THREADS;
42  import static org.jboss.hal.dmr.ModelDescriptionConstants.NAME;
43  import static org.jboss.hal.dmr.ModelDescriptionConstants.QUEUE_LENGTH;
44  import static org.jboss.hal.testsuite.container.WildFlyConfiguration.DEFAULT;
45  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.ALLOW_CORE_TIMEOUT;
46  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.LONG_RUNNING;
47  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.SHORT_RUNNING;
48  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.WM_THREAD_POOL_CREATE;
49  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.WM_THREAD_POOL_DELETE;
50  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.WM_THREAD_POOL_READ;
51  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.WM_THREAD_POOL_UPDATE;
52  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.longRunningAddress;
53  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.shortRunningAddress;
54  import static org.jboss.hal.testsuite.fixtures.JcaFixtures.workmanagerAddress;
55  import static org.junit.jupiter.api.Assertions.assertEquals;
56  
57  @Manatoko
58  @Testcontainers
59  class ThreadPoolTest {
60  
61      @Container static WildFlyContainer wildFly = WildFlyContainer.standalone(DEFAULT);
62  
63      @BeforeAll
64      static void setupModel() throws Exception {
65          OnlineManagementClient client = wildFly.managementClient();
66          Operations operations = new Operations(client);
67          operations.add(workmanagerAddress(WM_THREAD_POOL_CREATE), Values.of(NAME, WM_THREAD_POOL_CREATE));
68          addWorkmanagerWithThreadPools(operations, WM_THREAD_POOL_READ);
69          addWorkmanagerWithThreadPools(operations, WM_THREAD_POOL_UPDATE);
70          addWorkmanagerWithThreadPools(operations, WM_THREAD_POOL_DELETE);
71      }
72  
73      private static void addWorkmanagerWithThreadPools(Operations operations, String workmanager) throws Exception {
74          operations.add(workmanagerAddress(workmanager), Values.of(NAME, workmanager));
75          operations.add(longRunningAddress(workmanager), Values.of(MAX_THREADS, 10).and(QUEUE_LENGTH, 5));
76          operations.add(shortRunningAddress(workmanager), Values.of(MAX_THREADS, 10).and(QUEUE_LENGTH, 5));
77      }
78  
79      @Inject Console console;
80      @Inject CrudOperations crud;
81      @Page JcaPage page;
82      TableFragment wmTable;
83      TableFragment tpTable;
84      TabsFragment tpTabs;
85      FormFragment tpAttributesForm;
86      FormFragment tpSizingForm;
87  
88      @BeforeEach
89      void setUp() {
90          page.navigate();
91          console.verticalNavigation().selectPrimary(Ids.JCA_WORKMANAGER_ITEM);
92          wmTable = page.getWmTable();
93          tpTable = page.getWmThreadPoolTable();
94          tpTabs = page.getWmThreadPoolTabs();
95          tpAttributesForm = page.getWmThreadPoolAttributesForm();
96          tpSizingForm = page.getWmThreadPoolSizingForm();
97          tpTable.bind(asList(tpAttributesForm, tpSizingForm));
98      }
99  
100     @Test
101     void create() throws Exception {
102         wmTable.action(WM_THREAD_POOL_CREATE, Names.THREAD_POOLS);
103         waitGui().until().element(tpTable.getRoot()).is().visible();
104 
105         crud.create(longRunningAddress(WM_THREAD_POOL_CREATE), tpTable,
106                 form -> {
107                     form.number(MAX_THREADS, 10);
108                     form.number(QUEUE_LENGTH, 5);
109                 });
110 
111         crud.create(shortRunningAddress(WM_THREAD_POOL_CREATE), tpTable,
112                 form -> {
113                     form.number(MAX_THREADS, 10);
114                     form.number(QUEUE_LENGTH, 5);
115                 });
116     }
117 
118     @Test
119     void read() {
120         wmTable.action(WM_THREAD_POOL_READ, Names.THREAD_POOLS);
121         waitGui().until().element(tpTable.getRoot()).is().visible();
122 
123         tpTable.select(LONG_RUNNING);
124         tpTabs.select(Ids.build(Ids.JCA_WORKMANAGER, Ids.JCA_THREAD_POOL_ATTRIBUTES_TAB));
125         assertEquals(WM_THREAD_POOL_READ, tpAttributesForm.value(NAME));
126 
127         tpTable.select(SHORT_RUNNING);
128         tpTabs.select(Ids.build(Ids.JCA_WORKMANAGER, Ids.JCA_THREAD_POOL_ATTRIBUTES_TAB));
129         assertEquals(WM_THREAD_POOL_READ, tpAttributesForm.value(NAME));
130     }
131 
132     @Test
133     void update() throws Exception {
134         wmTable.action(WM_THREAD_POOL_UPDATE, Names.THREAD_POOLS);
135         waitGui().until().element(tpTable.getRoot()).is().visible();
136 
137         tpTable.select(LONG_RUNNING);
138         tpTabs.select(Ids.build(Ids.JCA_WORKMANAGER, Ids.JCA_THREAD_POOL_ATTRIBUTES_TAB));
139         crud.update(longRunningAddress(WM_THREAD_POOL_UPDATE), tpAttributesForm, ALLOW_CORE_TIMEOUT, true);
140 
141         tpTable.select(SHORT_RUNNING);
142         tpTabs.select(Ids.build(Ids.JCA_WORKMANAGER, Ids.JCA_THREAD_POOL_SIZING_TAB));
143         crud.update(shortRunningAddress(WM_THREAD_POOL_UPDATE), tpSizingForm, MAX_THREADS, 111);
144     }
145 
146     @Test
147     void delete() throws Exception {
148         wmTable.action(WM_THREAD_POOL_DELETE, Names.THREAD_POOLS);
149         waitGui().until().element(tpTable.getRoot()).is().visible();
150 
151         crud.delete(longRunningAddress(WM_THREAD_POOL_DELETE), tpTable, WM_THREAD_POOL_DELETE);
152         crud.delete(shortRunningAddress(WM_THREAD_POOL_DELETE), tpTable, WM_THREAD_POOL_DELETE);
153     }
154 }