1 /* 2 * Copyright 2022 The Android Open Source Project 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 * http://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 @file:JvmName("StressTest") 17 18 package androidx.work.integration.testapp 19 20 import android.util.Log 21 import androidx.work.Constraints 22 import androidx.work.ExistingWorkPolicy 23 import androidx.work.NetworkType 24 import androidx.work.OneTimeWorkRequestBuilder 25 import androidx.work.WorkManager 26 queueLotsOfWorkersnull27fun queueLotsOfWorkers(workManager: WorkManager) { 28 for (i in 1..1000) { 29 Log.i("TestWM", "Queueing $i worker") 30 val constraint = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build() 31 val uniqueName = "Worker-$i" 32 33 val worker = OneTimeWorkRequestBuilder<TestWorker>().setConstraints(constraint).build() 34 35 val worker2 = OneTimeWorkRequestBuilder<TestWorker>().setConstraints(constraint).build() 36 37 val worker3 = OneTimeWorkRequestBuilder<TestWorker>().setConstraints(constraint).build() 38 39 workManager 40 .beginUniqueWork(uniqueName, ExistingWorkPolicy.KEEP, worker) 41 .then(worker2) 42 .then(worker3) 43 .enqueue() 44 } 45 } 46