6
6
import io .getstream .chat .java .models .Channel .ChannelMemberRequestObject ;
7
7
import io .getstream .chat .java .models .Channel .ChannelRequestObject ;
8
8
import io .getstream .chat .java .models .Message .MessageRequestObject ;
9
+ import io .getstream .chat .java .models .TaskStatus .TaskStatusGetResponse ;
9
10
import io .getstream .chat .java .models .User .UserRequestObject ;
10
11
import io .getstream .chat .java .models .User .UserUpsertRequestData .UserUpsertRequest ;
11
12
import java .util .ArrayList ;
@@ -29,6 +30,7 @@ public class BasicTest {
29
30
static void setup () throws StreamException , SecurityException , IllegalArgumentException {
30
31
// failOnUnknownProperties();
31
32
setProperties ();
33
+ cleanChannels ();
32
34
cleanChannelTypes ();
33
35
cleanBlocklists ();
34
36
cleanCommands ();
@@ -37,6 +39,43 @@ static void setup() throws StreamException, SecurityException, IllegalArgumentEx
37
39
createTestMessage ();
38
40
}
39
41
42
+ private static void cleanChannels () throws StreamException {
43
+ while (true ) {
44
+ List <String > channels =
45
+ Channel .list ().request ().getChannels ().stream ()
46
+ .map (channel -> channel .getChannel ().getCId ())
47
+ .collect (Collectors .toList ());
48
+
49
+ if (channels .size () == 0 ) {
50
+ break ;
51
+ }
52
+
53
+ var deleteManyResponse =
54
+ Channel .deleteMany (channels ).setDeleteStrategy (DeleteStrategy .HARD ).request ();
55
+ String taskId = deleteManyResponse .getTaskId ();
56
+ Assertions .assertNotNull (taskId );
57
+
58
+ System .out .printf ("Waiting for channel deletion task %s to complete...\n " , taskId );
59
+
60
+ while (true ) {
61
+ TaskStatusGetResponse response = TaskStatus .get (taskId ).request ();
62
+ String status = response .getStatus ();
63
+
64
+ if (status .equals ("completed" ) || status .equals ("ok" )) {
65
+ break ;
66
+ }
67
+ if (status .equals ("failed" ) || status .equals ("error" )) {
68
+ throw new StreamException (
69
+ String .format ("Failed to delete channel(task_id: %s): %s" , response .getId (), status ),
70
+ (Throwable ) null );
71
+ }
72
+
73
+ // wait for the channels to delete
74
+ Assertions .assertDoesNotThrow (() -> Thread .sleep (500 ));
75
+ }
76
+ }
77
+ }
78
+
40
79
private static void cleanChannelTypes () throws StreamException {
41
80
ChannelType .list ()
42
81
.request ()
0 commit comments