Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
c414499b
Kaydet (Commit)
c414499b
authored
Eyl 12, 2012
tarafından
Stephan Bergmann
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Remove race conditions from test
Change-Id: I97e10fa3b9058211313a7faa5269d71e233f8bf8
üst
d19c40f4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
61 deletions
+28
-61
PipedConnection_Test.java
...t/com/sun/star/comp/connections/PipedConnection_Test.java
+28
-61
No files found.
jurt/test/com/sun/star/comp/connections/PipedConnection_Test.java
Dosyayı görüntüle @
c414499b
...
...
@@ -18,115 +18,82 @@
package
com
.
sun
.
star
.
comp
.
connections
;
import
com.sun.star.io.IOException
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
final
class
PipedConnection_Test
{
private
static
final
int
ROUNDS
=
2000
;
@Test
public
void
test
()
throws
Exception
{
PipedConnection
rightSide
=
new
PipedConnection
(
new
Object
[
0
]);
PipedConnection
leftSide
=
new
PipedConnection
(
new
Object
[]{
rightSide
});
byte
theByte
[]
=
new
byte
[
1
];
Reader
reader
=
new
Reader
(
rightSide
,
theByte
);
Writer
writer
=
new
Writer
(
leftSide
,
theByte
,
reader
);
Reader
reader
=
new
Reader
(
rightSide
);
Writer
writer
=
new
Writer
(
leftSide
);
reader
.
start
();
writer
.
start
();
Thread
.
sleep
(
2000
);
writer
.
term
();
writer
.
join
();
reader
.
join
();
assertTrue
(
writer
.
_state
);
assertTrue
(
reader
.
_state
);
assertEquals
(
ROUNDS
,
reader
.
_rounds
);
}
static
class
Reader
extends
Thread
{
private
static
class
Reader
extends
Thread
{
PipedConnection
_pipedConnection
;
byte
_theByte
[];
boolean
_quit
;
boolean
_state
=
false
;
int
_rounds
=
0
;
Reader
(
PipedConnection
pipedConnection
,
byte
theByte
[]
)
{
Reader
(
PipedConnection
pipedConnection
)
{
_pipedConnection
=
pipedConnection
;
_theByte
=
theByte
;
}
public
void
run
()
{
try
{
byte
bytes
[][]
=
new
byte
[
1
][];
while
(!
_quit
)
{
int
read
=
_pipedConnection
.
read
(
bytes
,
1
);
if
(
read
==
1
)
{
// System.err.println("read :" + bytes[0][0]);
if
(
_theByte
[
0
]
!=
bytes
[
0
][
0
])
throw
new
NullPointerException
();
synchronized
(
this
)
{
notifyAll
();
for
(
byte
v
=
0
;;
v
++)
{
byte
[][]
b
=
new
byte
[
1
][];
int
n
=
_pipedConnection
.
read
(
b
,
1
);
if
(
n
==
0
)
{
break
;
}
assertEquals
(
1
,
n
);
assertEquals
(
1
,
b
[
0
].
length
);
assertEquals
(
v
,
b
[
0
][
0
]);
++
_rounds
;
}
else
_quit
=
true
;
// EOF
}
_pipedConnection
.
close
();
_state
=
true
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
com
.
sun
.
star
.
io
.
IOException
ioException
)
{
System
.
err
.
println
(
"#### Reader - unexpected:"
+
ioException
);
}
}
}
static
class
Writer
extends
Thread
{
private
static
class
Writer
extends
Thread
{
PipedConnection
_pipedConnection
;
byte
_theByte
[];
Reader
_reader
;
boolean
_quit
;
boolean
_state
=
false
;
Writer
(
PipedConnection
pipedConnection
,
byte
theByte
[],
Reader
reader
)
{
Writer
(
PipedConnection
pipedConnection
)
{
_pipedConnection
=
pipedConnection
;
_reader
=
reader
;
_theByte
=
theByte
;
}
public
void
run
()
{
try
{
while
(!
_quit
)
{
synchronized
(
_reader
)
{
_pipedConnection
.
write
(
_theByte
);
byte
v
=
0
;
for
(
int
i
=
0
;
i
!=
ROUNDS
;
++
i
)
{
byte
[]
b
=
new
byte
[]
{
v
++
};
_pipedConnection
.
write
(
b
);
_pipedConnection
.
flush
();
// System.err.println("written :" + _theByte[0]);
_reader
.
wait
();
}
++
_theByte
[
0
];
}
_pipedConnection
.
close
();
_state
=
true
;
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
catch
(
com
.
sun
.
star
.
io
.
IOException
ioException
)
{
System
.
err
.
println
(
"#### Writer:"
+
ioException
);
}
catch
(
InterruptedException
interruptedException
)
{
System
.
err
.
println
(
"#### Writer:"
+
interruptedException
);
}
}
public
void
term
()
{
_quit
=
true
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment