42
42
import org .apache .hadoop .hdds .protocol .proto .HddsProtos .LifeCycleState ;
43
43
import org .apache .hadoop .hdds .protocol .proto .HddsProtos .ReplicationFactor ;
44
44
import org .apache .hadoop .hdds .scm .container .replication .ContainerReplicaPendingOps ;
45
+ import org .apache .hadoop .hdds .scm .container .states .ContainerStateMap ;
45
46
import org .apache .hadoop .hdds .scm .ha .SCMHAManager ;
46
47
import org .apache .hadoop .hdds .scm .ha .SCMHAManagerStub ;
47
48
import org .apache .hadoop .hdds .scm .ha .SequenceIdGenerator ;
53
54
import org .apache .hadoop .hdds .utils .db .DBStoreBuilder ;
54
55
import org .apache .hadoop .ozone .common .statemachine .InvalidStateTransitionException ;
55
56
import org .apache .hadoop .ozone .container .common .SCMTestUtils ;
57
+ import org .apache .ozone .test .GenericTestUtils ;
56
58
import org .junit .jupiter .api .AfterEach ;
59
+ import org .junit .jupiter .api .BeforeAll ;
57
60
import org .junit .jupiter .api .BeforeEach ;
58
61
import org .junit .jupiter .api .Test ;
59
62
import org .junit .jupiter .api .io .TempDir ;
63
+ import org .junit .jupiter .params .ParameterizedTest ;
64
+ import org .junit .jupiter .params .provider .EnumSource ;
65
+ import org .slf4j .event .Level ;
60
66
61
67
/**
62
68
* Tests to verify the functionality of ContainerManager.
@@ -72,6 +78,12 @@ public class TestContainerManagerImpl {
72
78
private NodeManager nodeManager ;
73
79
private ContainerReplicaPendingOps pendingOpsMock ;
74
80
81
+ @ BeforeAll
82
+ static void init () {
83
+ // Print container state transition logs
84
+ GenericTestUtils .setLogLevel (ContainerStateMap .getLogger (), Level .TRACE );
85
+ }
86
+
75
87
@ BeforeEach
76
88
void setUp () throws Exception {
77
89
final OzoneConfiguration conf = SCMTestUtils .getConf (testDir );
@@ -131,9 +143,12 @@ void testUpdateContainerState() throws Exception {
131
143
assertEquals (LifeCycleState .CLOSED , containerManager .getContainer (cid ).getState ());
132
144
}
133
145
134
- @ Test
135
- void testTransitionDeletingToClosedState () throws IOException , InvalidStateTransitionException {
136
- // allocate OPEN Ratis and Ec containers, and do a series of state changes to transition them to DELETING
146
+ @ ParameterizedTest
147
+ @ EnumSource (value = HddsProtos .LifeCycleState .class ,
148
+ names = {"DELETING" , "DELETED" })
149
+ void testTransitionDeletingOrDeletedToClosedState (HddsProtos .LifeCycleState desiredState )
150
+ throws IOException , InvalidStateTransitionException {
151
+ // Allocate OPEN Ratis and Ec containers, and do a series of state changes to transition them to DELETING / DELETED
137
152
final ContainerInfo container = containerManager .allocateContainer (
138
153
RatisReplicationConfig .getInstance (
139
154
ReplicationFactor .THREE ), "admin" );
@@ -162,29 +177,39 @@ void testTransitionDeletingToClosedState() throws IOException, InvalidStateTrans
162
177
assertEquals (LifeCycleState .DELETING , containerManager .getContainer (cid ).getState ());
163
178
assertEquals (LifeCycleState .DELETING , containerManager .getContainer (ecCid ).getState ());
164
179
165
- // DELETING -> CLOSED
166
- containerManager .transitionDeletingToClosedState (cid );
167
- containerManager .transitionDeletingToClosedState (ecCid );
180
+ if (desiredState == LifeCycleState .DELETED ) {
181
+ // DELETING -> DELETED
182
+ containerManager .updateContainerState (cid , HddsProtos .LifeCycleEvent .CLEANUP );
183
+ containerManager .updateContainerState (ecCid , HddsProtos .LifeCycleEvent .CLEANUP );
184
+ assertEquals (LifeCycleState .DELETED , containerManager .getContainer (cid ).getState ());
185
+ assertEquals (LifeCycleState .DELETED , containerManager .getContainer (ecCid ).getState ());
186
+ }
187
+
188
+ // DELETING / DELETED -> CLOSED
189
+ containerManager .transitionDeletingOrDeletedToClosedState (cid );
190
+ containerManager .transitionDeletingOrDeletedToClosedState (ecCid );
168
191
// the containers should be back in CLOSED state now
169
192
assertEquals (LifeCycleState .CLOSED , containerManager .getContainer (cid ).getState ());
170
193
assertEquals (LifeCycleState .CLOSED , containerManager .getContainer (ecCid ).getState ());
171
194
}
172
195
173
196
@ Test
174
- void testTransitionDeletingToClosedStateAllowsOnlyDeletingContainers () throws IOException {
197
+ void testTransitionContainerToClosedStateAllowOnlyDeletingOrDeletedContainers () throws IOException {
198
+ // Negative test for Ratis/EC container OPEN -> CLOSED transition
199
+
175
200
// test for RATIS container
176
201
final ContainerInfo container = containerManager .allocateContainer (
177
202
RatisReplicationConfig .getInstance (
178
203
ReplicationFactor .THREE ), "admin" );
179
204
final ContainerID cid = container .containerID ();
180
205
assertEquals (LifeCycleState .OPEN , containerManager .getContainer (cid ).getState ());
181
- assertThrows (IOException .class , () -> containerManager .transitionDeletingToClosedState (cid ));
206
+ assertThrows (IOException .class , () -> containerManager .transitionDeletingOrDeletedToClosedState (cid ));
182
207
183
208
// test for EC container
184
209
final ContainerInfo ecContainer = containerManager .allocateContainer (new ECReplicationConfig (3 , 2 ), "admin" );
185
210
final ContainerID ecCid = ecContainer .containerID ();
186
211
assertEquals (LifeCycleState .OPEN , containerManager .getContainer (ecCid ).getState ());
187
- assertThrows (IOException .class , () -> containerManager .transitionDeletingToClosedState (ecCid ));
212
+ assertThrows (IOException .class , () -> containerManager .transitionDeletingOrDeletedToClosedState (ecCid ));
188
213
}
189
214
190
215
@ Test
0 commit comments